By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,196 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,196 IT Pros & Developers. It's quick & easy.

Converting a vb application

P: n/a
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
--
Stefano Mora
email: *@*
(remove *)

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"SM" <st**********@hotmail.com> schrieb
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. :-)

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a
Hi,

You need to use a delegate for callback functions. Hope this
helps.

http://www.elitevb.com/content/01,0075,01/04.aspx

http://msdn.microsoft.com/library/de...classtopic.asp

Ken
--------------
"SM" <st**********@hotmail.com> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
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
--
Stefano Mora
email: *@*
(remove *)

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.