I wanted to pass ByVal a Me.Handle() to a CStyle DLL.
The code for the DLL is as follows:
void __stdcall WriteWindowHand le(HWND wHandle)
{
DATASTRUCT ds;
DWORD dwBytesWritten;
ds.wndHandle = wHandle;
m_pMem->Lock();
BOOL bSuccess = m_pMem->Write (
&ds, // Destination for data
sizeof(ds), // Number of bytes to write
&dwBytesWritten , // Buffer for count of bytes uploaded to shared memory
0 // Offset into shared memory buffer
);
m_pMem->Unlock();
return;
}
Using Visual Basic 6 a Long parameter is easily marshalled to HWND wHandle.
However using the VB.NET code written below I cannot find a way to marshal
Me.Handle() into the above HWND wHandle parameter. The code does compile,
but will not execute.
Public Class LibWrap
' Declare a managed prototype for the unmanaged function.
Declare Function WriteWindowHand le Lib _
"C:\Program Files\AmiBroker \Plugins\XLPlug in.dll" (ByVal i As Integer)
End Class 'LibWrap
' Blah Blah Blah
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
LibWrap.WriteWi ndowHandle(Me.H andle().ToInt32 ()) 'This line will not execute
'System.Runtime .InteropService s.MarshalDirect iveException' occurred in App5.exe
End Sub
The question is how can I marshal Me.Handle() into HWND wHandle.
The code for the DLL is as follows:
void __stdcall WriteWindowHand le(HWND wHandle)
{
DATASTRUCT ds;
DWORD dwBytesWritten;
ds.wndHandle = wHandle;
m_pMem->Lock();
BOOL bSuccess = m_pMem->Write (
&ds, // Destination for data
sizeof(ds), // Number of bytes to write
&dwBytesWritten , // Buffer for count of bytes uploaded to shared memory
0 // Offset into shared memory buffer
);
m_pMem->Unlock();
return;
}
Using Visual Basic 6 a Long parameter is easily marshalled to HWND wHandle.
However using the VB.NET code written below I cannot find a way to marshal
Me.Handle() into the above HWND wHandle parameter. The code does compile,
but will not execute.
Public Class LibWrap
' Declare a managed prototype for the unmanaged function.
Declare Function WriteWindowHand le Lib _
"C:\Program Files\AmiBroker \Plugins\XLPlug in.dll" (ByVal i As Integer)
End Class 'LibWrap
' Blah Blah Blah
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
LibWrap.WriteWi ndowHandle(Me.H andle().ToInt32 ()) 'This line will not execute
'System.Runtime .InteropService s.MarshalDirect iveException' occurred in App5.exe
End Sub
The question is how can I marshal Me.Handle() into HWND wHandle.
Comment