
Dear team,
My project is using vb6 and C language. The basic idea is using
Vb to pass a structure array to DLL .
Declare Sub Machine Lib "vcdll.dll" (ByRef myStruct As MyArrayStruct)
My structure is
Structure
Public setups(200) as integer
End Structure
This structure will to pass to VCdll and inside the DLL, its will create a thread (infinity loop). The structure data will be modified by time to time. These data will shown in VB6 display.
This project is successfully done. Any data change on VCdll will be seen in
Vb (Since both holding a same address of structure.
But the problem occurred will I use
VB.net. Since
VB.net do not allow to fixed a structure array size. Then I have follow the declaration below
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure MyArrayStruct
<VBFixedArray(199), MarshalAs(UnmanagedType.ByValArray, SizeConst:=200)> Public SETUPS() As Integer
End structure
Althrough,
VB.net and VCdll able to communicate, but the data update on
VB.net will not work accordingly.
For example
- VCdll (thread) => while (true){ struc.setup(0) ++; },
Vb.net can be only allow to update one time at the beginning, after end CALLBACK Machine(â¦.)
- I suspect
VB.net loss the common structure address.
-
===VCdll.dll
void __declspec(dllexport) CALLBACK Machine(struct machine *structMachine)
{
int i =1;
Pmac = structMachine;
threadID = _beginthread(PLC_PRG,1024,structMachine);
aaa = GetThreadPriority((HANDLE)threadID);
}
void PLC_PRG (void *mac)
{
i=1;
while(i)
{
Pmac ->SETUPS[0] ++;
Sleep(100);
if (Pmac ->SETUPS[0] > 100)
i=0;
}
}
The above shown Pmac ->SETUPS[0] always increment. I suppost can seen this increment in
VB.net. But not the case. (Its all right in VB6).
Andbody has any idea my mistake. Please advise me. I need it urgently,
Thanks a lot
Nick