Converting a vb application

S

SM

Hello group,
we are converting a VB6 application, written by other
people, for .NET Framework.
Original application depends on a DLL written in standard C.

The application communicates with an external device
using serial API functions located on the DLL.
Original developer write a VB function which makes a
call located in the DLL passing the instance and a function
pointer to a VB function. The DLL code creates an
invisible window with CreateWindow() function using
instance handle and function pointer (as WndProc,just
to handle a custom WM_xxx message).

Until the code was VB6/C code, it was OK.
Now, the code is, with a little modifications, VB.NET
and we receive an INVALID_HANDLE error on
CreateWindow() function.
I suppose the problem is on HINSTACE handle, cause
the VB.NET function used as WndProc receive a couple of
standard messages (WM_NCCREATE/WM_NCDESTROY).

We need to leave 'untouched' the DLL (now unmanaged).

How can we solve ?
Is it possible to use the VB.NET HINSTANCE in the same
way of the old VB HINSTANCE to create a new window in
a C ?

Thanks a lot,
regards
 
A

Armin Zingler

SM said:
Hello group,
we are converting a VB6 application, written by other
people, for .NET Framework.
Original application depends on a DLL written in standard C.

The application communicates with an external device
using serial API functions located on the DLL.
Original developer write a VB function which makes a
call located in the DLL passing the instance and a function
pointer to a VB function. The DLL code creates an
invisible window with CreateWindow() function using
instance handle and function pointer (as WndProc,just
to handle a custom WM_xxx message).

Until the code was VB6/C code, it was OK.
Now, the code is, with a little modifications, VB.NET
and we receive an INVALID_HANDLE error on
CreateWindow() function.
I suppose the problem is on HINSTACE handle, cause
the VB.NET function used as WndProc receive a couple of
standard messages (WM_NCCREATE/WM_NCDESTROY).

We need to leave 'untouched' the DLL (now unmanaged).

How can we solve ?
Is it possible to use the VB.NET HINSTANCE in the same
way of the old VB HINSTANCE to create a new window in
a C ?

This should work:

Imports System.Reflection
Imports System.Runtime.InteropServices

'...
Private Function GetHInstance() As IntPtr
Dim Assy As [Assembly]
Dim Modules As [Module]()

Assy = [Assembly].GetExecutingAssembly
Modules = Assy.GetModules
If Modules.Length > 0 Then 'rarely 0
Return Marshal.GetHINSTANCE(Modules(0))
End If

End Function

I don't know if this solves the mentioned problem and there might be other
approaches, but it should return the HInstance. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top