![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have some existing vb6 code that I am moving to a .net dll for easy access from both vb6 apps as well as vb.net apps. There are some custom api calls that use structures that have strings in them. I didn't think this would be a problem but I find that if I put a string in a structure it is no longer usable through com interop in a vb6 application. Is this correct or am I doing something wrong. .net example code: Public Structure test_type Public junk As String Public hello As Short End Structure |
|
vb6 example code: private sub command1_click() dim test as mylib.test_type test.junk = "12345" test.hello = 1776 end sub I get "Variable uses an automation type not supported in visual basic" error as soon as I click the button. I set a break point on test.junk = "12345" and it never makes it there. |
#3
| |||
| |||
|
|
Hi, I have some existing vb6 code that I am moving to a .net dll for easy access from both vb6 apps as well as vb.net apps. There are some custom api calls that use structures that have strings in them. I didn't think this would be a problem but I find that if I put a string in a structure it is no longer usable through com interop in a vb6 application. Is this correct or am I doing something wrong. .net example code: Public Structure test_type Public junk As String Public hello As Short End Structure In .Net structs are value types and can only consist of value type. Make it a class and you can put ref types like String in there. vb6 example code: private sub command1_click() dim test as mylib.test_type test.junk = "12345" test.hello = 1776 end sub I get "Variable uses an automation type not supported in visual basic" error as soon as I click the button. I set a break point on test.junk = "12345" and it never makes it there. Structs should not have worked in VB6 as automation types, too. How is mylib.test_type defined in VB6? -- SvenC |
#4
| |||
| |||
|
|
Hi, I have some existing vb6 code that I am moving to a .net dll for easy access from both vb6 apps as well as vb.net apps. There are some custom api calls that use structures that have strings in them. I didn't think this would be a problem but I find that if I put a string in a structure it is no longer usable through com interop in a vb6 application. Is this correct or am I doing something wrong. .net example code: Public Structure test_type Public junk As String Public hello As Short End Structure In .Net structs are value types and can only consist of value type. Make it a class and you can put ref types like String in there. |
|
vb6 example code: private sub command1_click() dim test as mylib.test_type test.junk = "12345" test.hello = 1776 end sub I get "Variable uses an automation type not supported in visual basic" error as soon as I click the button. I set a break point on test.junk = "12345" and it never makes it there. Structs should not have worked in VB6 as automation types, too. How is mylib.test_type defined in VB6? -- SvenC |
#5
| |||
| |||
|
|
"SvenC" <S... (AT) community (DOT) nospam> wrote in message news:CF59DE5D-0E9B-494D-A150-518EB5D490E1 (AT) microsoft (DOT) com... Hi, I have some existing vb6 code that I am moving to a .net dll for easy access from both vb6 apps as well as vb.net apps. There are some custom api calls that use structures that have strings in them. I didn't think this would be a problem but I find that if I put a string in a structure it is no longer usable through com interop in a vb6 application. Is this correct or am I doing something wrong. .net example code: Public Structure test_type Public junk As String Public hello As Short End Structure In .Net structs are value types and can only consist of value type. Make it a class and you can put ref types like String in there. Total nonsense. A reference is itself just a value, and you certainly can have references inside structs. The trouble is that there are many many ways to pass a string through p/invoke, and you have to tell it which. I think there's a MarshalAsAttribute that should come with good examples. vb6 example code: private sub command1_click() dim test as mylib.test_type test.junk = "12345" test.hello = 1776 end sub I get "Variable uses an automation type not supported in visual basic" error as soon as I click the button. I set a break point on test.junk = "12345" and it never makes it there. Structs should not have worked in VB6 as automation types, too. How is mylib.test_type defined in VB6? -- SvenC- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - |
#6
| |||
| |||
|
|
On Jun 27, 10:55 pm, "Ben Voigt [C++ MVP]" <r... (AT) nospam (DOT) nospam> wrote: "SvenC" <S... (AT) community (DOT) nospam> wrote in message news:CF59DE5D-0E9B-494D-A150-518EB5D490E1 (AT) microsoft (DOT) com... Hi, I have some existing vb6 code that I am moving to a .net dll for easy access from both vb6 apps as well as vb.net apps. There are some custom api calls that use structures that have strings in them. I didn't think this would be a problem but I find that if I put a string in a structure it is no longer usable through com interop in a vb6 application. Is this correct or am I doing something wrong. .net example code: Public Structure test_type Public junk As String Public hello As Short End Structure In .Net structs are value types and can only consist of value type. Make it a class and you can put ref types like String in there. Total nonsense. A reference is itself just a value, and you certainly can have references inside structs. The trouble is that there are many many ways to pass a string through p/invoke, and you have to tell it which. I think there's a MarshalAsAttribute that should come with good examples. vb6 example code: private sub command1_click() dim test as mylib.test_type test.junk = "12345" test.hello = 1776 end sub I get "Variable uses an automation type not supported in visual basic" error as soon as I click the button. I set a break point on test.junk = "12345" and it never makes it there. Structs should not have worked in VB6 as automation types, too. How is mylib.test_type defined in VB6? -- SvenC- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - I'm glad to hear that it should be possible. The VB6 to .net upgrade wizard translated: MakeCode As String * MakeCodeSize_int_gc to: VBFixedString(MakeCodeSize_int_gc), System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray, SizeConst:=MakeCodeSize_int_gc)> Public MakeCode() As Char This is what generates the "Variable uses an automation type not supported in visual basic" error. Because of your message here I tried other options including the SafeArray instead of ByValArray and it works. It isn't size limited like it is supposed to be though. It should be restricted to MakecodeSize_int_gc. If you know the proper MarshalAs type for a fixed length string I would appreciate knowing. I will play with it in the mean time and see if I can figure it out. Thanks for the response. Raymond |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |