summaryrefslogtreecommitdiff
path: root/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h
blob: bf767271fb23d30068a5323dd83a608da00178a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
#include "platformdefines.cpp"
#include <xplatform.h>

const int NumArrElements = 2;
struct InnerSequential
{
	int f1;
	float f2;
	LPCSTR f3;
};
void PrintInnerSequential(InnerSequential* p, char const * name)
{
	printf("\t%s.f1 = %d\n", name, p->f1);
	printf("\t%s.f2 = %f\n", name, p->f2);
	printf("\t%s.f3 = %s\n", name, p->f3);
}

void ChangeInnerSequential(InnerSequential* p)
{
	p->f1 = 77;
	p->f2 = 77.0;

	char const * lpstr = "changed string";
	size_t size = sizeof(char) * (strlen(lpstr) + 1);
	LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size );
	memset(temp, 0, size);
	if(temp)
	{
		strcpy( (char*)temp, lpstr );
		p->f3 = temp;
	}
	else
	{
		printf("Memory Allocated Failed!");
	}
}

bool IsCorrectInnerSequential(InnerSequential* p)
{
	if(p->f1 != 1)
		return false;
	if(p->f2 != 1.0)
		return false;

	char const * lpstr = "some string";
	size_t size = sizeof(char) * (strlen(lpstr) + 1);
	LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size );
	memset(temp, 0, size);

	if( strcmp((char*)p->f3, temp) != 0 )
		return false;

	return true;
}

#ifndef WINDOWS
typedef int INT;
typedef unsigned int UINT;
typedef short SHORT;
typedef char CHAR;
typedef unsigned short WORD;
typedef short SHORT;
typedef float FLOAT;
typedef double DOUBLE;
#endif

struct INNER2 // size = 12 bytes
{
    INT f1;
    FLOAT f2;
    LPCSTR f3;
};
void ChangeINNER2(INNER2* p)
{
	p->f1 = 77;
	p->f2 = 77.0;
	char const * temp = "changed string";
	size_t len = strlen(temp);
	LPCSTR str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) );
	strcpy((char*)str,temp);
	p->f3 = str;
}
void PrintINNER2(INNER2* p, char const * name)
{
	printf("\t%s.f1 = %d\n", name, p->f1);
	printf("\t%s.f2 = %f\n", name, p->f2);
	printf("\t%s.f3 = %s\n", name, p->f3);
}
bool IsCorrectINNER2(INNER2* p)
{
	if(p->f1 != 1)
		return false;
	if(p->f2 != 1.0)
		return false;
	if(memcmp(p->f3, "some string",11*sizeof(char)) != 0 )
		return false;
	return true;
}


struct InnerExplicit 
{
	#ifdef WINDOWS
    union
    {
        INT f1;
        FLOAT f2;
    };
	CHAR _unused0[4];
    LPCSTR f3;
	#endif 

	#ifndef WINDOWS
    union
    {
        INT f1;
        FLOAT f2;
    };
	INT _unused0;
    LPCSTR f3;
	#endif 
};


void PrintInnerExplicit(InnerExplicit* p, char const * name)
{
	printf("\t%s.f1 = %d\n", name, p->f1);
	printf("\t%s.f2 = %f\n", name, p->f2);
	printf("\t%s.f3 = %s\n", name, p->f3);
}

void ChangeInnerExplicit(InnerExplicit* p)
{
	p->f1 = 77;

	char const * temp = "changed string";
	size_t len = strlen(temp);
	LPCSTR str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) );
	strcpy((char*)str,temp);
	p->f3 = str;
}

struct InnerArraySequential
{
	InnerSequential arr[NumArrElements];
};

void PrintInnerArraySequential(InnerArraySequential* p, char const * name)
{
	for(int i = 0; i < NumArrElements; i++)
	{
		printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
		printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
		printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3);
	}
}

void ChangeInnerArraySequential(InnerArraySequential* p)
{
	char const * lpstr = "changed string";
	LPSTR temp;
	for(int i = 0; i < NumArrElements; i++)
	{
		(p->arr)[i].f1 = 77;
		(p->arr)[i].f2 = 77.0;

		size_t size = sizeof(char) * (strlen(lpstr) + 1);
		temp = (LPSTR)TP_CoTaskMemAlloc( size );
		memset(temp, 0, size);
		if(temp)
		{
			strcpy( (char*)temp, lpstr );
			(p->arr)[i].f3 = temp;
		}
		else
		{
			printf("Memory Allocated Failed!");
		}
	}
}

bool IsCorrectInnerArraySequential(InnerArraySequential* p)
{
	for(int i = 0; i < NumArrElements; i++)
	{
		if( (p->arr)[i].f1 != 1 )
			return false;
		if( (p->arr)[i].f2 != 1.0 )
			return false;
	}
	return true;
}


union InnerArrayExplicit // size = 32 bytes
{
	struct InnerSequential arr[2];
	struct
	{
		LONG64 _unused0;
		LPCSTR f4;
	}; 

};


#ifdef WINDOWS
	#ifdef _WIN64
		union OUTER3 // size = 32 bytes
		{
			struct InnerSequential arr[2];
			struct
			{
				CHAR _unused0[24];
				LPCSTR f4;
			};
		};
	#else
		struct OUTER3 // size = 28 bytes
		{
			struct InnerSequential arr[2];
			LPCSTR f4;
		};
	#endif
#endif

#ifndef WINDOWS
	struct OUTER3 // size = 28 bytes
	{
		struct InnerSequential arr[2];
		LPCSTR f4;
	};
#endif

void PrintOUTER3(OUTER3* p, char const * name)
{
	for(int i = 0; i < NumArrElements; i++)
	{
		printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
		printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
		printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3);
	}
	printf("\t%s.f4 = %s\n",name,p->f4);
}
void ChangeOUTER3(OUTER3* p)
{
	char const * temp = "changed string";
	size_t len = strlen(temp);
	LPCSTR str = NULL;
	for(int i = 0; i < NumArrElements; i++)
	{
		(p->arr)[i].f1 = 77;
		(p->arr)[i].f2 = 77.0;
	
		str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) );
		strcpy((char*)str,temp);
		(p->arr)[i].f3 = str;
	}

	str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) );
	strcpy((char*)str,temp);
	p->f4 = str;
}
bool IsCorrectOUTER3(OUTER3* p)
{
	for(int i = 0; i < NumArrElements; i++)
	{
		if( (p->arr)[i].f1 != 1 )
			return false;
		if( (p->arr)[i].f2 != 1.0 )
			return false;
		if( memcmp((p->arr)[i].f3, "some string",11*sizeof(char)) != 0 )
			return false;
	}
	if(memcmp(p->f4,"some string",11*sizeof(char)) != 0)
	{
		return false;
	}
	return true;
}

struct CharSetAnsiSequential
{
    LPCSTR f1;
    char f2;
};

void PrintCharSetAnsiSequential(CharSetAnsiSequential* p, char const * name)
{
	printf("\t%s.f1 = %s\n", name, p->f1);
	printf("\t%s.f2 = %c\n", name, p->f2);
}

void ChangeCharSetAnsiSequential(CharSetAnsiSequential* p)
{
	char const * strSource = "change string";
	size_t size = strlen(strSource) + 1;
	LPSTR temp = (LPSTR)TP_CoTaskMemAlloc(size);
	if(temp != NULL)
	{
		strcpy((char*)temp,strSource);
		p->f1 = temp;
		p->f2 = 'n';
	}
	else
	{
		printf("Memory Allocated Failed!");
	}
}

bool IsCorrectCharSetAnsiSequential(CharSetAnsiSequential* p)
{
	if(strcmp((char*)p->f1, (char*)"some string") != 0 )
		return false;
	if(p->f2 != 'c')
		return false;
	return true;
}


struct CharSetUnicodeSequential 
{
    LPCWSTR f1;
    WCHAR f2;
};
void PrintCharSetUnicodeSequential(CharSetUnicodeSequential* p, char const * name)
{
	wprintf(L"\t%s.f1 = %S\n", name, p->f1);
	printf("\t%s.f2 = %c\n", name, p->f2);
}

void ChangeCharSetUnicodeSequential(CharSetUnicodeSequential* p)
{
#ifdef _WIN32
	LPCWSTR strSource = L"change string";
#else
	LPCWSTR strSource = u"change string";
#endif
	int len = wcslen(strSource);
	LPCWSTR temp = (LPCWSTR)TP_CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
	if(temp != NULL)
	{
		wcscpy_s((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource);
		p->f1 = temp;
		p->f2 = L'n';
	}
	else
	{
		printf("Memory Allocated Failed!");
	}
}

bool IsCorrectCharSetUnicodeSequential(CharSetUnicodeSequential* p)
{
#ifdef _WIN32
	LPCWSTR expected= L"some string";
#else
	LPCWSTR expected= u"some string";
#endif
	LPCWSTR actual = p->f1;
	if(0 != TP_wcmp_s((WCHAR*)actual, (WCHAR*)expected))
	{
		return false;
	}
	if(p->f2 != L'c')
	{
		return false;
	}
	return true;
}


struct NumberSequential // size = 64 bytes
{
	LONG64 i64;
	ULONG64 ui64;
	DOUBLE d;
    INT i32;		
    UINT ui32;		
    SHORT s1;		
    WORD us1;	
	SHORT i16;		
    WORD ui16;
	FLOAT sgl;
    BYTE b;			
    CHAR sb;		  
};
void PrintNumberSequential(NumberSequential* str, char const * name)
{
	printf("\t%s.i32 = %d\n", name, str->i32);
	printf("\t%s.ui32 = %d\n", name, str->ui32);
	printf("\t%s.s1 = %d\n", name, str->s1);
	printf("\t%s.us1 = %u\n", name, str->us1);
	printf("\t%s.b = %u\n", name, str->b);
	printf("\t%s.sb = %d\n", name, str->sb);
	printf("\t%s.i16 = %d\n", name, str->i16);
	printf("\t%s.ui16 = %u\n", name, str->ui16);
	printf("\t%s.i64 = %lld\n", name, str->i64);
	printf("\t%s.ui64 = %llu\n", name, str->ui64);
	printf("\t%s.sgl = %f\n", name, str->sgl);
	printf("\t%s.d = %f\n",name, str->d);
}
void ChangeNumberSequential(NumberSequential* p)
{
	p->i32 = 0;
	p->ui32 = 32;
	p->s1 = 0;
	p->us1 = 16;
	p->b = 0;
	p->sb = 8;
	p->i16 = 0;
	p->ui16 = 16;
	p->i64 = 0;
	p->ui64 = 64;
	p->sgl = 64.0;
	p->d = 6.4;
}

bool IsCorrectNumberSequential(NumberSequential* p)
{
	if(p->i32 != -0x80000000 || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 || 
		p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 ||
		p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
	{
		return false;
	}
	return true;
}

struct S3 // size = 1032 bytes
{
    BOOL flag;
    LPCSTR str;
    INT vals[256];
};

void PrintS3(S3* str, char const * name)
{
	printf("\t%s.flag = %d\n", name, str->flag);
	printf("\t%s.str = %s\n", name, str->str);
	for(int i = 0; i<256 ;i++)
	{
		printf("\t%s.vals[%d] = %d\n",name,i,str->vals[i]);
	}
}

void ChangeS3(S3* p)
{
	p->flag = false;

	char const * strSource = "change string";
	int len = strlen(strSource);
	
	LPCSTR temp = (LPCSTR)TP_CoTaskMemAlloc((sizeof(char)*len) + 1);
	if(temp != NULL)
	{
		/*TP_CoTaskMemFree((void *)p->str);*/
		strcpy((char*)temp,strSource);		
		p->str = temp;
	}
	for(int i = 1;i<257;i++)
	{
		p->vals[i-1] = i;
	}
}

bool IsCorrectS3(S3* p)
{
	int iflag = 0;

	char const * lpstr = "some string";
	size_t size = sizeof(char) * (strlen(lpstr) + 1);
	LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size );
	memset(temp, 0, size);

	if(!p->flag || strcmp((char*)p->str, temp) != 0)
		return false;
    for (int i = 0; i < 256; i++)
    {
        if (p->vals[i] != i)
        {
            printf("\tThe Index of %i is not expected",i);
            iflag++;
        }
    }
    if (iflag != 0)
    {
        return false;
    }
	return true;
}

struct S4 // size = 8 bytes
{
    INT age;
    LPCSTR name;
};
enum Enum1 
{
    e1 = 1,
    e2 = 3 
};
struct S5 // size = 8 bytes
{
    struct S4 s4;
    Enum1 ef;
};

void PrintS5(S5* str, char const * name)
{
	printf("\t%s.s4.age = %d", name, str->s4.age);
	printf("\t%s.s4.name = %s", name, str->s4.name);
	printf("\t%s.ef = %d", name, str->ef);
}
void ChangeS5(S5* str)
{
	Enum1 eInstance = e2;
	char const * strSource = "change string";	
	int len = strlen(strSource);
	LPCSTR temp = (LPCSTR)TP_CoTaskMemAlloc(sizeof(char)*(len+1));
	if(temp != NULL)
	{
		strcpy((char*)temp,strSource);
		str->s4.name = temp;
	}
	str->s4.age = 64;
	str->ef = eInstance;
}
bool IsCorrectS5(S5* str)
{
	Enum1 eInstance = e1;

	char const * lpstr = "some string";
	size_t size = sizeof(char) * (strlen(lpstr) + 1);
	LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size );
	memset(temp, 0, size);

	if(str->s4.age != 32 || strcmp((char*)str->s4.name, temp) != 0)
		return false;
	if(str->ef != eInstance)
	{
		return false;
	}
	return true;
}

struct StringStructSequentialAnsi // size = 8 bytes
{
	LPCSTR first;
    LPCSTR last;
};

void PrintStringStructSequentialAnsi(StringStructSequentialAnsi* str, char const * name)
{
	printf("\t%s.first = %s\n", name, str->first);
	printf("\t%s.last = %s\n", name, str->last);
}

bool IsCorrectStringStructSequentialAnsi(StringStructSequentialAnsi* str)
{
	char strOne[512];
	char strTwo[512];
	for(int i = 0;i<512;i++)
	{
		strOne[i] = 'a';
		strTwo[i] = 'b';
	}

	if(memcmp(str->first,strOne,512)!= 0)
		return false;

	if(memcmp(str->last,strTwo,512)!= 0)
		return false;

	return true;
}

void ChangeStringStructSequentialAnsi(StringStructSequentialAnsi* str)
{
	char* newFirst = (char*)TP_CoTaskMemAlloc(sizeof(char)*513);
	char* newLast = (char*)TP_CoTaskMemAlloc(sizeof(char)*513);
	for (int i = 0; i < 512; ++i)
	{
		newFirst[i] = 'b';
		newLast[i] = 'a';
	}
	newFirst[512] = '\0';
	newLast[512] = '\0';

	str->first = newFirst;	
	str->last = newLast;
}

struct StringStructSequentialUnicode // size = 8 bytes
{
    LPCWSTR first;
    LPCWSTR last;
};

void PrintStringStructSequentialUnicode(StringStructSequentialUnicode* str, char const * name)
{
	wprintf(L"\t%s.first = %s\n", name, str->first);
	wprintf(L"\t%s.last = %s\n", name, str->last);
}

bool IsCorrectStringStructSequentialUnicode(StringStructSequentialUnicode* str)
{
	WCHAR strOne[256+1];
	WCHAR strTwo[256+1];

	for(int i = 0;i<256;++i)
	{
		strOne[i] = L'a';
		strTwo[i] = L'b';
	}
	strOne[256] = L'\0';
	strTwo[256] = L'\0';

	if(memcmp(str->first,strOne,256*sizeof(WCHAR)) != 0)
		return false;
	if(memcmp(str->last,strTwo,256*sizeof(WCHAR)) != 0)
		return false;
	return true;
}

void ChangeStringStructSequentialUnicode(StringStructSequentialUnicode* str)
{
	WCHAR* newFirst = (WCHAR*)TP_CoTaskMemAlloc(sizeof(WCHAR)*257);
	WCHAR* newLast = (WCHAR*)TP_CoTaskMemAlloc(sizeof(WCHAR)*257);
	for (int i = 0; i < 256; ++i)
	{
		newFirst[i] = L'b';
		newLast[i] = L'a';
	}
	newFirst[256] = L'\0';
	newLast[256] = L'\0';
	str->first = (const WCHAR*)newFirst;
	str->last = (const WCHAR*)newLast;
}


struct S8 // size = 32 bytes
{
    LPCSTR name;
    BOOL gender;
    INT i32;
    UINT ui32;
	WORD jobNum;
    CHAR mySByte;
};
void PrintS8(S8* str, char const * name)
{
	printf("\t%s.name = %s\n",name, str->name);
	printf("\t%s.gender = %d\n", name, str->gender);
	printf("\t%s.jobNum = %d\n",name, str->jobNum);
	printf("\t%s.i32 = %d\n", name, str->i32);
	printf("\t%s.ui32 = %u\n", name, str->ui32);
	printf("\t%s.mySByte = %c\n", name, str->mySByte);
}
bool IsCorrectS8(S8* str)
{
	if(memcmp( str->name,"hello", strlen("hello")*sizeof(char)+1 )!= 0)
		return false;
	if(!str->gender)
		return false;
	if(str->jobNum != 10)
		return false;
	if(str->i32!= 128 || str->ui32 != 128)
		return false;
	if(str->mySByte != 32)
		return false;
	return true;
}

void ChangeS8(S8* str)
{
	char const * lpstr = "world";
	size_t size = sizeof(char) * (strlen(lpstr) + 1);
	LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size );
	memset(temp, 0, size);
	if(temp)
	{
		strcpy( (char*)temp, lpstr );
		str->name = temp;
	}
	else
	{
		printf("Memory Allocated Failed!");
	}
	str->gender = false;
	str->jobNum = 1;
	str->i32 = 256;
	str->ui32 = 256;
	str->mySByte = 64;
}
#pragma pack (8)
struct S_int // size = 4 bytes
{
    INT i;
};

struct S9;
typedef void (*TestDelegate1)(struct S9 myStruct);

struct S9 // size = 8 bytes
{
    INT i32;
    TestDelegate1 myDelegate1;
};

struct S101 // size = 8 bytes
{
    INT i;
    struct S_int s_int;
};

struct S10 // size = 8 bytes
{
    struct S101 s;
};
void PrintS10(S10* str, char const * name)
{
	printf("\t%s.s.s_int.i = %d\n", name, str->s.s_int.i);
	printf("\t%s.s.i = %d\n", name, str->s.i);
}
bool IsCorrectS10(S10* str)
{
	if(str->s.s_int.i != 32)
		return false;
	if(str->s.i != 32)
		return false;
	return true;
}
void ChangeS10(S10* str)
{
	str->s.s_int.i = 64;
	str->s.i = 64;
}

#ifndef WINDOWS
typedef int* LPINT;
#endif

struct S11 // size = 8 bytes
{
    LPINT i32;
    INT i;
};

union U // size = 8 bytes
{
    INT i32;
    UINT ui32;
    LPVOID iPtr;
    LPVOID uiPtr;
    SHORT s;
    WORD us;
    BYTE b;
    CHAR sb;
    LONG64 l;
    ULONG64 ul;
    FLOAT f;
    DOUBLE d;
};

void PrintU(U* str, char const * name)
{
	printf("\t%s.i32 = %d\n", name, str->i32);
	printf("\t%s.ui32 = %u\n", name, str->ui32);
	printf("\t%s.iPtr = %p\n", name, str->iPtr);
	printf("\t%s.uiPtr = %p\n", name, str->uiPtr);
	printf("\t%s.s = %d\n", name, str->s);
	printf("\t%s.us = %u\n", name, str->us);
	printf("\t%s.b = %u\n", name, str->b);
	printf("\t%s.sb = %d\n", name, str->sb);
	printf("\t%s.l = %lld\n", name, str->l);
	printf("\t%s.ul = %llu\n", name, str->ul);
	printf("\t%s.f = %f\n", name, str->f);
	printf("\t%s.d = %f\n", name, str->d);
}

void ChangeU(U* p)
{
	p->i32 = 2147483647;
	p->ui32 = 0;
	p->iPtr = (LPVOID)(-64);
	p->uiPtr = (LPVOID)(64);
	p->s = 32767;
	p->us = 0;
	p->b = -1;
	p->sb = -128;
	p->l = -1234567890;
	p->ul = 0;
	p->f = 64.0;
	p->d = 6.4;
}

bool IsCorrectU(U* p)
{
	if(p->d != 3.2)
	{
		return false;
	}
	return true;
}

struct ByteStructPack2Explicit // size = 2 bytes
{
    BYTE b1;
    BYTE b2;
};
void PrintByteStructPack2Explicit(ByteStructPack2Explicit* str, char const * name)
{
	printf("\t%s.b1 = %d", name, str->b1);
	printf("\t%s.b2 = %d", name, str->b2);
}

void ChangeByteStructPack2Explicit(ByteStructPack2Explicit* p)
{
	p->b1 = 64;
	p->b2 = 64;
}
bool IsCorrectByteStructPack2Explicit(ByteStructPack2Explicit* p)
{
	if(p->b1 != 32 || p->b2 != 32)
		return false;
	return true;
}



struct ShortStructPack4Explicit // size = 4 bytes
{
    SHORT s1;
    SHORT s2;
};

void PrintShortStructPack4Explicit(ShortStructPack4Explicit* str, char const * name)
{
	printf("\t%s.s1 = %d", name, str->s1);
	printf("\t%s.s2 = %d", name, str->s2);
}
void ChangeShortStructPack4Explicit(ShortStructPack4Explicit* p)
{
	p->s1 = 64;
	p->s2 = 64;
}
bool IsCorrectShortStructPack4Explicit(ShortStructPack4Explicit* p)
{
	if(p->s1 != 32 || p->s2 != 32)
		return false;
	return true;
}


struct IntStructPack8Explicit // size = 8 bytes
{
    INT i1;
    INT i2;
};

void PrintIntStructPack8Explicit(IntStructPack8Explicit* str, char const * name)
{
	printf("\t%s.i1 = %d", name, str->i1);
	printf("\t%s.i2 = %d", name, str->i2);
}
void ChangeIntStructPack8Explicit(IntStructPack8Explicit* p)
{
	p->i1 = 64;
	p->i2 = 64;
}
bool IsCorrectIntStructPack8Explicit(IntStructPack8Explicit* p)
{
	if(p->i1 != 32 || p->i2 != 32)
		return false;
	return true;
}

struct LongStructPack16Explicit // size = 16 bytes
{
    LONG64 l1;
    LONG64 l2;
};

void PrintLongStructPack16Explicit(LongStructPack16Explicit* str, char const * name)
{
	printf("\t%s.l1 = %lld", name, str->l1);
	printf("\t%s.l2 = %lld", name, str->l2);
}
void ChangeLongStructPack16Explicit(LongStructPack16Explicit* p)
{
	p->l1 = 64;
	p->l2 = 64;
}
bool IsCorrectLongStructPack16Explicit(LongStructPack16Explicit* p)
{
	if(p->l1 != 32 || p->l2 != 32)
		return false;
	return true;
}