-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodExporter.bas
2336 lines (2216 loc) · 96.7 KB
/
modExporter.bas
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
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "modExporter"
'MIT License
'
'Copyright (c) 2020 0xAA55-Official-Org
'
'Permission is hereby granted, free of charge, to any person obtaining a copy
'of this software and associated documentation files (the "Software"), to deal
'in the Software without restriction, including without limitation the rights
'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'copies of the Software, and to permit persons to whom the Software is
'furnished to do so, subject to the following conditions:
'
'The above copyright notice and this permission notice shall be included in all
'copies or substantial portions of the Software.
'
'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
'SOFTWARE.
Option Explicit
'Merge two dictionaries
Function MergeDict(Dict1 As Dictionary, Dict2 As Dictionary) As Dictionary
Dim Ret As New Dictionary
Dim Key
For Each Key In Dict1.Keys
Ret.Item(Key) = Dict1(Key)
Next
For Each Key In Dict2.Keys
Ret.Item(Key) = Dict2(Key)
Next
Set MergeDict = Ret
End Function
Function MatchPrefix(ByVal Str_ As String, ByVal Prefix As String, Optional ByVal CaseSensitive As Boolean = True) As Boolean
If CaseSensitive Then
If Left$(Str_, Len(Prefix)) = Prefix Then MatchPrefix = True
Else
If Left$(UCase$(Str_), Len(Prefix)) = UCase$(Prefix) Then MatchPrefix = True
End If
End Function
'Do type conversions
Function DoTypeConvVB_NET(TypeDesc As String) As String
Select Case TypeDesc
Case "GLenum"
DoTypeConvVB_NET = "UInt32"
Case "GLbitfield"
DoTypeConvVB_NET = "UInt32"
Case "GLuint"
DoTypeConvVB_NET = "UInt32"
Case "GLint"
DoTypeConvVB_NET = "Int32"
Case "GLsizei"
DoTypeConvVB_NET = "Int32"
Case "GLboolean"
DoTypeConvVB_NET = "Boolean"
Case "GLbyte"
DoTypeConvVB_NET = "Byte"
Case "GLshort"
DoTypeConvVB_NET = "Int16"
Case "GLubyte"
DoTypeConvVB_NET = "Byte"
Case "GLushort"
DoTypeConvVB_NET = "UInt16"
Case "GLulong"
DoTypeConvVB_NET = "UIntPtr"
Case "GLfloat"
DoTypeConvVB_NET = "Single"
Case "GLclampf"
DoTypeConvVB_NET = "Single"
Case "GLdouble"
DoTypeConvVB_NET = "Double"
Case "GLclampd"
DoTypeConvVB_NET = "Double"
Case "GLvoid"
DoTypeConvVB_NET = "IntPtr"
Case "GLint64EXT"
DoTypeConvVB_NET = "Int64"
Case "GLuint64EXT"
DoTypeConvVB_NET = "UInt64"
Case "GLint64"
DoTypeConvVB_NET = "Int64"
Case "GLuint64"
DoTypeConvVB_NET = "UInt64"
Case "GLsync"
DoTypeConvVB_NET = "IntPtr"
Case "GLchar"
DoTypeConvVB_NET = "Byte"
Case "GLintptr"
DoTypeConvVB_NET = "IntPtr"
Case "GLsizeiptr"
DoTypeConvVB_NET = "IntPtr"
Case "GLfixed"
DoTypeConvVB_NET = "Int32"
Case "cl_context"
DoTypeConvVB_NET = "IntPtr"
Case "cl_event"
DoTypeConvVB_NET = "IntPtr"
Case "GLcharARB"
DoTypeConvVB_NET = "Byte"
Case "GLhandleARB"
DoTypeConvVB_NET = "Int32"
Case "GLintptrARB"
DoTypeConvVB_NET = "IntPtr"
Case "GLsizeiptrARB"
DoTypeConvVB_NET = "IntPtr"
Case "GLeglClientBufferEXT"
DoTypeConvVB_NET = "UIntPtr"
Case "GLhalf"
DoTypeConvVB_NET = "UInt16"
Case "GLvdpauSurfaceNV"
DoTypeConvVB_NET = "IntPtr"
Case "GLclampx"
DoTypeConvVB_NET = "Int32"
Case "HPBUFFERARB"
DoTypeConvVB_NET = "IntPtr"
Case "HPBUFFEREXT"
DoTypeConvVB_NET = "IntPtr"
Case "HGPUNV"
DoTypeConvVB_NET = "IntPtr"
Case "HVIDEOOUTPUTDEVICENV"
DoTypeConvVB_NET = "IntPtr"
Case "HVIDEOINPUTDEVICENV"
DoTypeConvVB_NET = "IntPtr"
Case "HPVIDEODEV"
DoTypeConvVB_NET = "IntPtr"
Case "FLOAT"
DoTypeConvVB_NET = "Single"
Case "float"
DoTypeConvVB_NET = "Single"
Case "UINT"
DoTypeConvVB_NET = "UInt32"
Case "int"
DoTypeConvVB_NET = "Int32"
Case "INT"
DoTypeConvVB_NET = "Int32"
Case "unsigned int"
DoTypeConvVB_NET = "UInt32"
Case "unsigned long"
DoTypeConvVB_NET = "UIntPtr"
Case "BOOL"
DoTypeConvVB_NET = "Boolean"
Case "USHORT"
DoTypeConvVB_NET = "UInt16"
Case "DWORD"
DoTypeConvVB_NET = "UInt32"
Case "HDC"
DoTypeConvVB_NET = "IntPtr"
Case "HGLRC"
DoTypeConvVB_NET = "IntPtr"
Case "HANDLE"
DoTypeConvVB_NET = "IntPtr"
Case "LPVOID"
DoTypeConvVB_NET = "IntPtr"
Case "PGPU_DEVICE"
DoTypeConvVB_NET = "IntPtr"
Case "GLUquadric"
DoTypeConvVB_NET = "IntPtr"
Case "GLUtesselator"
DoTypeConvVB_NET = "IntPtr"
Case "GLUnurbs"
DoTypeConvVB_NET = "IntPtr"
Case Else
DoTypeConvVB_NET = TypeDesc
Debug.Print TypeDesc
End Select
End Function
'Do type conversion but only for the return type
Function DoRetTypeConvVB_NET(RetType As String) As String
Dim Trimmed As String
Trimmed = Trim$(Replace(RetType, "const ", ""))
If InStr(Trimmed, "*") Then
Trimmed = Replace(Trimmed, " *", "*")
Select Case Trimmed
'You don't want the memory allocated from an API as a return value freed by CLR
Case "GLubyte*"
DoRetTypeConvVB_NET = "IntPtr"
Case "GLchar*"
DoRetTypeConvVB_NET = "IntPtr"
Case "char*"
DoRetTypeConvVB_NET = "IntPtr"
Case "void*"
DoRetTypeConvVB_NET = "IntPtr"
Case "wchar_t*"
DoRetTypeConvVB_NET = "IntPtr"
Case Else
DoRetTypeConvVB_NET = "IntPtr"
Debug.Print Trimmed
End Select
Else
DoRetTypeConvVB_NET = DoTypeConvVB_NET(Trimmed)
End If
End Function
'Do type conversions
Function DoTypeConvCSharp(TypeDesc As String) As String
Select Case TypeDesc
Case "void"
DoTypeConvCSharp = "void"
Case "VOID"
DoTypeConvCSharp = "void"
Case "GLenum"
DoTypeConvCSharp = "uint"
Case "GLbitfield"
DoTypeConvCSharp = "uint"
Case "GLuint"
DoTypeConvCSharp = "uint"
Case "GLint"
DoTypeConvCSharp = "int"
Case "GLsizei"
DoTypeConvCSharp = "int"
Case "GLboolean"
DoTypeConvCSharp = "bool"
Case "GLbyte"
DoTypeConvCSharp = "byte"
Case "GLshort"
DoTypeConvCSharp = "short"
Case "GLubyte"
DoTypeConvCSharp = "byte"
Case "GLushort"
DoTypeConvCSharp = "ushort"
Case "GLulong"
DoTypeConvCSharp = "UIntPtr"
Case "GLfloat"
DoTypeConvCSharp = "float"
Case "GLclampf"
DoTypeConvCSharp = "float"
Case "GLdouble"
DoTypeConvCSharp = "double"
Case "GLclampd"
DoTypeConvCSharp = "double"
Case "GLvoid"
DoTypeConvCSharp = "IntPtr"
Case "GLint64EXT"
DoTypeConvCSharp = "long"
Case "GLuint64EXT"
DoTypeConvCSharp = "ulong"
Case "GLint64"
DoTypeConvCSharp = "long"
Case "GLuint64"
DoTypeConvCSharp = "ulong"
Case "GLsync"
DoTypeConvCSharp = "IntPtr"
Case "GLchar"
DoTypeConvCSharp = "byte"
Case "GLintptr"
DoTypeConvCSharp = "IntPtr"
Case "GLsizeiptr"
DoTypeConvCSharp = "IntPtr"
Case "GLfixed"
DoTypeConvCSharp = "int"
Case "cl_context"
DoTypeConvCSharp = "IntPtr"
Case "cl_event"
DoTypeConvCSharp = "IntPtr"
Case "GLcharARB"
DoTypeConvCSharp = "byte"
Case "GLhandleARB"
DoTypeConvCSharp = "uint"
Case "GLintptrARB"
DoTypeConvCSharp = "IntPtr"
Case "GLsizeiptrARB"
DoTypeConvCSharp = "IntPtr"
Case "GLeglClientBufferEXT"
DoTypeConvCSharp = "UIntPtr"
Case "GLhalf"
DoTypeConvCSharp = "ushort"
Case "GLvdpauSurfaceNV"
DoTypeConvCSharp = "IntPtr"
Case "GLclampx"
DoTypeConvCSharp = "int"
Case "HPBUFFERARB"
DoTypeConvCSharp = "IntPtr"
Case "HPBUFFEREXT"
DoTypeConvCSharp = "IntPtr"
Case "HGPUNV"
DoTypeConvCSharp = "IntPtr"
Case "HVIDEOOUTPUTDEVICENV"
DoTypeConvCSharp = "IntPtr"
Case "HVIDEOINPUTDEVICENV"
DoTypeConvCSharp = "IntPtr"
Case "HPVIDEODEV"
DoTypeConvCSharp = "IntPtr"
Case "FLOAT"
DoTypeConvCSharp = "float"
Case "float"
DoTypeConvCSharp = "float"
Case "UINT"
DoTypeConvCSharp = "uint"
Case "int"
DoTypeConvCSharp = "int"
Case "INT"
DoTypeConvCSharp = "int"
Case "unsigned int"
DoTypeConvCSharp = "uint"
Case "unsigned long"
DoTypeConvCSharp = "UIntPtr"
Case "BOOL"
DoTypeConvCSharp = "bool"
Case "USHORT"
DoTypeConvCSharp = "ushort"
Case "DWORD"
DoTypeConvCSharp = "uint"
Case "HDC"
DoTypeConvCSharp = "IntPtr"
Case "HGLRC"
DoTypeConvCSharp = "IntPtr"
Case "HANDLE"
DoTypeConvCSharp = "IntPtr"
Case "LPVOID"
DoTypeConvCSharp = "IntPtr"
Case "PGPU_DEVICE"
DoTypeConvCSharp = "IntPtr"
Case "GLUquadric"
DoTypeConvCSharp = "IntPtr"
Case "GLUtesselator"
DoTypeConvCSharp = "IntPtr"
Case "GLUnurbs"
DoTypeConvCSharp = "IntPtr"
Case Else
DoTypeConvCSharp = TypeDesc
Debug.Print TypeDesc
End Select
End Function
'Do type conversion but only for the return type
Function DoRetTypeConvCSharp(RetType As String) As String
Dim Trimmed As String
Trimmed = Trim$(Replace(RetType, "const ", ""))
If InStr(Trimmed, "*") Then
Trimmed = Replace(Trimmed, " *", "*")
Select Case Trimmed
'You don't want the memory allocated from an API as a return value freed by CLR
Case "GLubyte*"
DoRetTypeConvCSharp = "IntPtr"
Case "GLchar*"
DoRetTypeConvCSharp = "IntPtr"
Case "char*"
DoRetTypeConvCSharp = "IntPtr"
Case "void*"
DoRetTypeConvCSharp = "IntPtr"
Case "wchar_t*"
DoRetTypeConvCSharp = "IntPtr"
Case Else
DoRetTypeConvCSharp = "IntPtr"
Debug.Print Trimmed
End Select
Else
DoRetTypeConvCSharp = DoTypeConvCSharp(Trimmed)
End If
End Function
'Do type conversions
Function DoTypeConvCSharpUnsafe(TypeDesc As String) As String
Select Case TypeDesc
Case "void"
DoTypeConvCSharpUnsafe = "void"
Case "VOID"
DoTypeConvCSharpUnsafe = "void"
Case "GLenum"
DoTypeConvCSharpUnsafe = "uint"
Case "GLbitfield"
DoTypeConvCSharpUnsafe = "uint"
Case "GLuint"
DoTypeConvCSharpUnsafe = "uint"
Case "GLint"
DoTypeConvCSharpUnsafe = "int"
Case "GLsizei"
DoTypeConvCSharpUnsafe = "int"
Case "GLboolean"
DoTypeConvCSharpUnsafe = "bool"
Case "GLbyte"
DoTypeConvCSharpUnsafe = "byte"
Case "GLshort"
DoTypeConvCSharpUnsafe = "short"
Case "GLubyte"
DoTypeConvCSharpUnsafe = "byte"
Case "GLushort"
DoTypeConvCSharpUnsafe = "ushort"
Case "GLulong"
DoTypeConvCSharpUnsafe = "UIntPtr"
Case "GLfloat"
DoTypeConvCSharpUnsafe = "float"
Case "GLclampf"
DoTypeConvCSharpUnsafe = "float"
Case "GLdouble"
DoTypeConvCSharpUnsafe = "double"
Case "GLclampd"
DoTypeConvCSharpUnsafe = "double"
Case "GLvoid"
DoTypeConvCSharpUnsafe = "void"
Case "GLint64EXT"
DoTypeConvCSharpUnsafe = "long"
Case "GLuint64EXT"
DoTypeConvCSharpUnsafe = "ulong"
Case "GLint64"
DoTypeConvCSharpUnsafe = "long"
Case "GLuint64"
DoTypeConvCSharpUnsafe = "ulong"
Case "GLsync"
DoTypeConvCSharpUnsafe = "void*"
Case "GLchar"
DoTypeConvCSharpUnsafe = "byte"
Case "GLintptr"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "GLsizeiptr"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "GLfixed"
DoTypeConvCSharpUnsafe = "int"
Case "cl_context"
DoTypeConvCSharpUnsafe = "void*"
Case "cl_event"
DoTypeConvCSharpUnsafe = "void*"
Case "GLcharARB"
DoTypeConvCSharpUnsafe = "byte"
Case "GLhandleARB"
DoTypeConvCSharpUnsafe = "uint"
Case "GLintptrARB"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "GLsizeiptrARB"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "GLeglClientBufferEXT"
DoTypeConvCSharpUnsafe = "void*"
Case "GLhalf"
DoTypeConvCSharpUnsafe = "ushort"
Case "GLvdpauSurfaceNV"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "GLclampx"
DoTypeConvCSharpUnsafe = "int"
Case "HPBUFFERARB"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "HPBUFFEREXT"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "HGPUNV"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "HVIDEOOUTPUTDEVICENV"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "HVIDEOINPUTDEVICENV"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "HPVIDEODEV"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "FLOAT"
DoTypeConvCSharpUnsafe = "float"
Case "float"
DoTypeConvCSharpUnsafe = "float"
Case "UINT"
DoTypeConvCSharpUnsafe = "uint"
Case "int"
DoTypeConvCSharpUnsafe = "int"
Case "INT"
DoTypeConvCSharpUnsafe = "int"
Case "unsigned int"
DoTypeConvCSharpUnsafe = "uint"
Case "unsigned long"
DoTypeConvCSharpUnsafe = "UIntPtr"
Case "BOOL"
DoTypeConvCSharpUnsafe = "bool"
Case "USHORT"
DoTypeConvCSharpUnsafe = "ushort"
Case "DWORD"
DoTypeConvCSharpUnsafe = "uint"
Case "HDC"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "HGLRC"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "HANDLE"
DoTypeConvCSharpUnsafe = "IntPtr"
Case "LPVOID"
DoTypeConvCSharpUnsafe = "void*"
Case "PGPU_DEVICE"
DoTypeConvCSharpUnsafe = "void*"
Case "GLUquadric"
DoTypeConvCSharpUnsafe = "void*"
Case "GLUtesselator"
DoTypeConvCSharpUnsafe = "void*"
Case "GLUnurbs"
DoTypeConvCSharpUnsafe = "void*"
Case Else
DoTypeConvCSharpUnsafe = TypeDesc
Debug.Print TypeDesc
End Select
End Function
Function GetPointerLevel(TypeDesc As String) As Long
Dim I As Long
Do
I = InStr(I + 1, TypeDesc, "*")
GetPointerLevel = GetPointerLevel + 1
Loop While I
GetPointerLevel = GetPointerLevel - 1
End Function
'Rename the parameters if necessary
Function DoParamRenameVB_NET(Param As String, Optional DefaultName As String = "param") As String
Dim Trimmed As String
Dim HaveConst As Boolean
If InStr(Param, "const ") Then HaveConst = True
If InStr(Param, "const*") Then HaveConst = True
Trimmed = Trim$(Replace(Param, "const ", ""))
Trimmed = Trim$(Replace(Trimmed, "const*", "*"))
Trimmed = Replace(Trimmed, "*", "* ")
Trimmed = Replace(Trimmed, " ", " ")
Trimmed = Replace(Trimmed, " *", "*")
Dim PassType As String, ParamType As String, ParamName As String
Dim DelimPos As Long, IsReserved As Boolean
DelimPos = InStrRev(Trimmed, " ")
If DelimPos Then
ParamType = Left$(Trimmed, DelimPos - 1)
ParamName = Mid$(Trimmed, DelimPos + 1)
Select Case LCase$(ParamName)
Case "": ParamName = DefaultName 'The param only has it's type
Case "type": IsReserved = True
Case "end": IsReserved = True
Case "string": IsReserved = True
Case "object": IsReserved = True
Case "option": IsReserved = True
Case "event": IsReserved = True
Case "in": IsReserved = True
Case "error": IsReserved = True
Case "property": IsReserved = True
End Select
If IsReserved Then ParamName = ParamName & "_"
Else
ParamType = Trimmed
ParamName = DefaultName
End If
If InStr(ParamName, "[") Then
ParamType = ParamType & "*"
ParamName = Left$(ParamName, InStr(ParamName, "[") - 1)
End If
'Determine if using IntPtr is needed or just use ByRef
Select Case GetPointerLevel(ParamType)
Case 0
PassType = ""
ParamType = DoTypeConvVB_NET(ParamType)
Case 1
Select Case ParamType
Case "void*"
PassType = ""
ParamType = "IntPtr"
Case "GLvoid*"
PassType = ""
ParamType = "IntPtr"
Case "char*"
If HaveConst Then
PassType = "<MarshalAs(UnmanagedType.LPStr)> "
ParamType = "String"
Else
PassType = "<MarshalAs(UnmanagedType.LPStr)> "
ParamType = "StringBuilder"
End If
Case "GLchar*"
If HaveConst Then
PassType = "<MarshalAs(UnmanagedType.LPStr)> "
ParamType = "String"
Else
PassType = "<MarshalAs(UnmanagedType.LPStr)> "
ParamType = "StringBuilder"
End If
Case "wchar_t*"
If HaveConst Then
PassType = "<MarshalAs(UnmanagedType.LPWStr)> "
ParamType = "String"
Else
PassType = "<MarshalAs(UnmanagedType.LPWStr)> "
ParamType = "StringBuilder"
End If
Case Else
If HaveConst Then
PassType = "<MarshalAs(UnmanagedType.LPArray)> "
ParamType = DoTypeConvVB_NET(Replace(ParamType, "*", "")) & "()"
Else
PassType = "ByRef "
ParamType = DoTypeConvVB_NET(Replace(ParamType, "*", ""))
End If
End Select
Case 2
Select Case ParamType
Case "char**"
If HaveConst Then
PassType = "<MarshalAs(UnmanagedType.LPArray)> "
ParamType = "String()"
Else
PassType = "<MarshalAs(UnmanagedType.LPArray)> ByRef "
ParamType = "String()"
End If
Case "GLchar**"
If HaveConst Then
PassType = "<MarshalAs(UnmanagedType.LPArray)> "
ParamType = "String()"
Else
PassType = "<MarshalAs(UnmanagedType.LPArray)> ByRef "
ParamType = "String()"
End If
Case "wchar_t**"
If HaveConst Then
PassType = "<MarshalAs(UnmanagedType.LPArray)> "
ParamType = "IntPtr()"
Else
PassType = "<MarshalAs(UnmanagedType.LPArray)> ByRef "
ParamType = "IntPtr()"
End If
Case Else
If HaveConst Then
PassType = ""
ParamType = "IntPtr"
Else
PassType = "ByRef "
ParamType = "IntPtr"
End If
End Select
Case Else
PassType = "ByRef "
ParamType = "IntPtr"
End Select
Select Case ParamType
Case "Object"
PassType = "<MarshalAs(UnmanagedType.AsAny)> "
Case "Boolean"
PassType = "<MarshalAs(UnmanagedType.Bool)> " & PassType
End Select
DoParamRenameVB_NET = PassType & ParamName & " As " & ParamType
End Function
Function TheFunctionIsglGetSomething(ByVal FunctionName As String) As Boolean
If MatchPrefix(FunctionName, "PFNGLGET", False) Or _
MatchPrefix(FunctionName, "PFNWGLGET", False) Or _
MatchPrefix(FunctionName, "glGet", True) Or _
MatchPrefix(FunctionName, "wglGet", True) Then TheFunctionIsglGetSomething = True
End Function
Function TheFunctionIsglGenSomething(ByVal FunctionName As String) As Boolean
If MatchPrefix(FunctionName, "PFNGLGEN", False) Or _
MatchPrefix(FunctionName, "PFNWGLGEN", False) Or _
MatchPrefix(FunctionName, "glGen", True) Or _
MatchPrefix(FunctionName, "wglGen", True) Then TheFunctionIsglGenSomething = True
End Function
'Rename the parameters if necessary
Function DoParamRenameCSharp(Param As String, Optional DefaultName As String = "param", Optional ByVal FunctionName As String = "", Optional OutCallingParam As String = "", Optional ByVal NoMarshal As Boolean = False) As String
Dim Trimmed As String
Dim HaveConst As Boolean
If InStr(Param, "const ") Then HaveConst = True
If InStr(Param, "const*") Then HaveConst = True
Trimmed = Trim$(Replace(Param, "const ", ""))
Trimmed = Trim$(Replace(Trimmed, "const*", "*"))
Trimmed = Replace(Trimmed, "*", "* ")
Trimmed = Replace(Trimmed, " ", " ")
Trimmed = Replace(Trimmed, " *", "*")
Dim MarshalType As String, PassType As String, ParamType As String, ParamName As String
Dim DelimPos As Long, IsReserved As Boolean
DelimPos = InStrRev(Trimmed, " ")
If DelimPos Then
ParamType = Left$(Trimmed, DelimPos - 1)
ParamName = Mid$(Trimmed, DelimPos + 1)
Select Case LCase$(ParamName)
Case "": ParamName = DefaultName 'The param only has it's type
Case "type": IsReserved = True
Case "end": IsReserved = True
Case "string": IsReserved = True
Case "object": IsReserved = True
Case "option": IsReserved = True
Case "event": IsReserved = True
Case "in": IsReserved = True
Case "error": IsReserved = True
Case "property": IsReserved = True
Case "ref": IsReserved = True
Case "params": IsReserved = True
Case "base": IsReserved = True
End Select
If IsReserved Then ParamName = ParamName & "_"
Else
ParamType = Trimmed
ParamName = DefaultName
End If
If InStr(ParamName, "[") Then
ParamType = ParamType & "*"
ParamName = Left$(ParamName, InStr(ParamName, "[") - 1)
End If
'Determine if using IntPtr is needed or just use ref
Select Case GetPointerLevel(ParamType)
Case 0
ParamType = DoTypeConvCSharp(ParamType)
Case 1
Select Case ParamType
Case "void*"
ParamType = "IntPtr"
Case "GLvoid*"
ParamType = "IntPtr"
Case "char*"
MarshalType = "[MarshalAs(UnmanagedType.LPStr)] "
If HaveConst Then
ParamType = "string"
Else
ParamType = "StringBuilder"
End If
Case "GLchar*"
MarshalType = "[MarshalAs(UnmanagedType.LPStr)] "
If HaveConst Then
ParamType = "string"
Else
ParamType = "StringBuilder"
End If
Case "wchar_t*"
MarshalType = "[MarshalAs(UnmanagedType.LPWStr)] "
If HaveConst Then
ParamType = "string"
Else
ParamType = "StringBuilder"
End If
Case Else
If HaveConst Then
MarshalType = "[MarshalAs(UnmanagedType.LPArray)] "
ParamType = DoTypeConvCSharp(Replace(ParamType, "*", "")) & "[]"
Else
PassType = "ref "
ParamType = DoTypeConvCSharp(Replace(ParamType, "*", ""))
End If
End Select
Case 2
Select Case ParamType
Case "char**"
ParamType = "string[]"
If HaveConst = False Then PassType = "ref "
Case "GLchar**"
MarshalType = "[MarshalAs(UnmanagedType.LPArray)] "
ParamType = "string[]"
If HaveConst = False Then PassType = "ref "
Case "wchar_t**"
MarshalType = "[MarshalAs(UnmanagedType.LPArray)] "
ParamType = "IntPtr[]"
If HaveConst = False Then PassType = "ref "
Case Else
ParamType = "IntPtr"
If HaveConst = False Then PassType = "ref "
End Select
Case Else
PassType = "ref "
ParamType = "IntPtr"
End Select
Select Case ParamType
Case "Object"
MarshalType = "[MarshalAs(UnmanagedType.AsAny)] "
Case "bool"
MarshalType = "[MarshalAs(UnmanagedType.Bool)] "
End Select
OutCallingParam = PassType & ParamName
If NoMarshal = False Then DoParamRenameCSharp = MarshalType
DoParamRenameCSharp = DoParamRenameCSharp & PassType & ParamType & " " & ParamName
End Function
'Rename the parameters if necessary
Function DoParamRenameCSharpUnsafe(Param As String, Optional DefaultName As String = "param", Optional ByVal FunctionName As String = "", Optional OutCallingParam As String = "", Optional ByVal NoMarshal As Boolean = False) As String
Dim Trimmed As String
Dim HaveConst As Boolean
If InStr(Param, "const ") Then HaveConst = True
If InStr(Param, "const*") Then HaveConst = True
Trimmed = Trim$(Replace(Param, "const ", ""))
Trimmed = Trim$(Replace(Trimmed, "const*", "*"))
Trimmed = Replace(Trimmed, "*", "* ")
Trimmed = Replace(Trimmed, " ", " ")
Trimmed = Replace(Trimmed, " *", "*")
Dim MarshalType As String, PassType As String, ParamType As String, ParamName As String
Dim DelimPos As Long, IsReserved As Boolean
DelimPos = InStrRev(Trimmed, " ")
If DelimPos Then
ParamType = Left$(Trimmed, DelimPos - 1)
ParamName = Mid$(Trimmed, DelimPos + 1)
Select Case LCase$(ParamName)
Case "": ParamName = DefaultName 'The param only has it's type
Case "type": IsReserved = True
Case "end": IsReserved = True
Case "string": IsReserved = True
Case "object": IsReserved = True
Case "option": IsReserved = True
Case "event": IsReserved = True
Case "in": IsReserved = True
Case "error": IsReserved = True
Case "property": IsReserved = True
Case "ref": IsReserved = True
Case "params": IsReserved = True
Case "base": IsReserved = True
End Select
If IsReserved Then ParamName = ParamName & "_"
Else
ParamType = Trimmed
ParamName = DefaultName
End If
If InStr(ParamName, "[") Then
ParamType = ParamType & "*"
ParamName = Left$(ParamName, InStr(ParamName, "[") - 1)
End If
'Determine if using IntPtr is needed or just use ByRef
Select Case GetPointerLevel(ParamType)
Case 0
ParamType = DoTypeConvCSharpUnsafe(ParamType)
Case 1
Select Case ParamType
Case "void*"
ParamType = "void*"
Case "GLvoid*"
ParamType = "void*"
Case "char*"
MarshalType = "[MarshalAs(UnmanagedType.LPStr)] "
If HaveConst Then
ParamType = "string"
Else
ParamType = "StringBuilder"
End If
Case "GLchar*"
MarshalType = "[MarshalAs(UnmanagedType.LPStr)] "
If HaveConst Then
ParamType = "string"
Else
ParamType = "StringBuilder"
End If
Case "wchar_t*"
MarshalType = "[MarshalAs(UnmanagedType.LPWStr)] "
If HaveConst Then
ParamType = "string"
Else
ParamType = "StringBuilder"
End If
Case Else
ParamType = DoTypeConvCSharpUnsafe(Replace(ParamType, "*", "")) & "*"
End Select
Case 2
Select Case ParamType
Case "char**"
MarshalType = "[MarshalAs(UnmanagedType.LPArray)] "
ParamType = "string[]"
If HaveConst = False Then PassType = "ref "
Case "GLchar**"
MarshalType = "[MarshalAs(UnmanagedType.LPArray)] "
ParamType = "string[]"
If HaveConst = False Then PassType = "ref "
Case "wchar_t**"
MarshalType = "[MarshalAs(UnmanagedType.LPArray)] "
ParamType = "IntPtr[]"
If HaveConst = False Then PassType = "ref "
Case Else
ParamType = DoTypeConvCSharpUnsafe(Replace(ParamType, "*", "")) & "**"
End Select
Case Else
ParamType = DoTypeConvCSharpUnsafe(Replace(ParamType, "*", "")) & String(GetPointerLevel(ParamType), "*")
End Select
Select Case ParamType
Case "Object"
MarshalType = "[MarshalAs(UnmanagedType.AsAny)] "
Case "bool"
MarshalType = "[MarshalAs(UnmanagedType.Bool)] "
End Select
OutCallingParam = PassType & ParamName
If NoMarshal = False Then DoParamRenameCSharpUnsafe = MarshalType
DoParamRenameCSharpUnsafe = DoParamRenameCSharpUnsafe & PassType & ParamType & " " & ParamName
End Function
'Do type conversion but only for the return type
Function DoRetTypeConvCSharpUnsafe(RetType As String) As String
Dim Trimmed As String
Trimmed = Trim$(Replace(RetType, "const ", ""))
If InStr(Trimmed, "*") Then
Trimmed = Replace(Trimmed, " *", "*")
Select Case Trimmed
'You don't want the memory allocated from an API as a return value freed by CLR
Case "GLubyte*"
DoRetTypeConvCSharpUnsafe = "byte*"
Case "GLchar*"
DoRetTypeConvCSharpUnsafe = "byte*"
Case "char*"
DoRetTypeConvCSharpUnsafe = "byte*"
Case "void*"
DoRetTypeConvCSharpUnsafe = "void*"
Case "wchar_t*"
DoRetTypeConvCSharpUnsafe = "char*"
Case Else
DoRetTypeConvCSharpUnsafe = "void*"
Debug.Print Trimmed
End Select
Else
DoRetTypeConvCSharpUnsafe = DoTypeConvCSharpUnsafe(Trimmed)
End If
End Function
Function GuessConstMacroDefType(MacroDefs As Dictionary, MacroName, OutMacroDef As String) As String
Dim MacroDef As String
MacroDef = MacroDefs(MacroName)
OutMacroDef = MacroDef
Do While MacroDefs.Exists(MacroDef)
MacroDef = MacroDefs(MacroDef)
Loop
If IsNumeric(MacroDef) Then
If Int(MacroDef) = Val(MacroDef) And Abs(MacroDef) <= 4294967295# Then
GuessConstMacroDefType = "int "
Else
GuessConstMacroDefType = "double "
End If
ElseIf Left$(MacroDef, 2) = "0x" Then
If Right$(MacroDef, 3) = "ull" Then
GuessConstMacroDefType = "ulong "
If OutMacroDef = MacroDef Then OutMacroDef = Left$(OutMacroDef, Len(OutMacroDef) - 3)
ElseIf Right$(MacroDef, 1) = "u" Or Right$(MacroDef, 2) = "ul" Then
GuessConstMacroDefType = "uint "
Else
GuessConstMacroDefType = "int "
Dim Value As Long
Value = CLng("&H" & Mid$(MacroDef, 3))
If Value < 0 Then OutMacroDef = "unchecked((int)" & MacroDef & ")"
End If
Else
GuessConstMacroDefType = "string "
End If
End Function
Function CHex2VBHex(CHexStr As String) As String
If Left$(CHexStr, 2) = "0x" Then
If Len(CHexStr) = 6 Then
CHex2VBHex = "&H0" & Mid$(CHexStr, 3)
Else
CHex2VBHex = "&H" & Mid$(CHexStr, 3)
End If
Else
CHex2VBHex = CHexStr
End If
If UCase$(Right$(CHex2VBHex, 3)) = "ULL" Then CHex2VBHex = Left$(CHex2VBHex, Len(CHex2VBHex) - 3)
If UCase$(Right$(CHex2VBHex, 2)) = "LL" Then CHex2VBHex = Left$(CHex2VBHex, Len(CHex2VBHex) - 2)
If UCase$(Right$(CHex2VBHex, 2)) = "UL" Then CHex2VBHex = Left$(CHex2VBHex, Len(CHex2VBHex) - 2)
If UCase$(Right$(CHex2VBHex, 1)) = "L" Then CHex2VBHex = Left$(CHex2VBHex, Len(CHex2VBHex) - 1)
If UCase$(Right$(CHex2VBHex, 1)) = "U" Then CHex2VBHex = Left$(CHex2VBHex, Len(CHex2VBHex) - 1)
End Function
Sub ExportVB_NET(Parser As clsParser, ExportTo As String)
Dim GLExtString
Dim Ext As clsGLExtension
Dim MacroName
Dim FuncTypeDefName
Dim FuncPtrType
Dim FuncName
Dim I As Long, ExtCount As Long
Dim FuncData() As String
Dim Param() As String
Dim Tail As String
Dim AlreadyDefinedMacros As New Dictionary
Dim LabelUsed As Boolean
Dim FN As Integer
FN = FreeFile
Open ExportTo & "\modGL_API.vb" For Output As #FN
Print #FN, "Imports System.Runtime.InteropServices"
Print #FN, "Imports System.Text"
Print #FN,
Print #FN, "Module GL_API"
Print #FN,
Print #FN, "#Region ""OpenGL Extension Declerations"""
For Each GLExtString In Parser.GLExtension.Keys
Dim HasMacro As Boolean, HasAPI As Boolean, HasFuncPtr As Boolean
HasMacro = False
HasAPI = False
HasFuncPtr = False
Set Ext = Parser.GLExtension(GLExtString)
Print #FN, "#Region """; GLExtString; """"
Print #FN, vbTab; "' ----------------------------- "; GLExtString; " -----------------------------"
Print #FN,
'A variable tells you if this extension is available
Print #FN, vbTab; "Public "; GLExtString; " As Boolean = False"
Print #FN,
'Macro definitions
For Each MacroName In Ext.MacroDefs.Keys
HasMacro = True
'Make sure no duplicated
If AlreadyDefinedMacros.Exists(MacroName) = False Then