|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
C++ DLL Usage (p/invoke?)DLL control written in C++ using MFC -- it is a graphical routine that takes place primarily in OnPaint. Is there a way to insert this into VB? If so are there examples I could download? My primary concerns are 1) where to put this in the VB project, and 2) Converting C++ parameters to .Net variable types. I'm looking at the technique of using platform invoke described here: http://www.codeproject.com/dotnet/PInvoke.asp?print=true 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); I'm trying the following in Form1.vb but can seem to get it to work: <DllImport("MyMFCDLL.dll")> Public Shared Function CreateCtrl(ByVal prnt As Object, ByVal top As Int32, ByVal left As Int32, ByVal bottom As Int32, ByVal right As Int32, ByVal id As UInt32) As Boolean End Function Thanks. "Dave" <onlinef***@gmail.com> wrote: No. Its first argument is CWnd, an MFC wrapper around a win32 window>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); (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
What Does This Mean?
cant assign variable values to property in Class file Best way to write to textfiles? Re: .net Visual Studio timer1.stop VS 2005 SP1? A Simple SQL Result displayed into a TextBox Keeping Code Snippets? how can I tell if it is a folder or a non-folder file DataGridView visible columns |
|||||||||||||||||||||||