Re: C++ DLL Usage (p/invoke?)



"Dave" <onlinefuel@xxxxxxxxx> wrote:
Is there a way to import the following C++ 'create' command into VB?
BOOL CreateCtrl(CWnd* pParentWnd, int top, int left, int bottom, int
right, UINT nID, DWORD dwStyle = WS_VISIBLE);

No. Its first argument is CWnd, an MFC wrapper around a win32 window
(also known as HWND or Handle). But VB will only give you
..net/winforms wrappers around Handles.

Did you write the DLL, or someone else? If you have the source code,
maybe you can recode it a little to take a HWND as its first argument.
I know enough MFC to believe that this is possible, but have no solid
ideas. Once you've done this,

Public Shared Function CreateCtrl(ByVal prnt As IntPtr, ...)

NB. You seemed to be missing the final dwStyle argument? That's
compulsory in your declaration of CreateCtrl. Also, you had it return
a Boolean. I don't think that's right. I think you have to use
Interop.Marshal to convert an mfc BOOL into a VB Boolean. I don't know
the VB syntax. Here's an example of the c# syntax for marshalling a
bool:
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool OpenClipboard(IntPtr hwnd);



If you don't have the source code then the solution is more
horrendous. You'd write your own MFC container, one which has one of
these controls inside it, but which accepts an HWND as its parent.

--
Lucian
.



Relevant Pages


Loading