473,396 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C++ DLL Usage (p/invoke?)

Hello, I have little experience with VB or .Net in general but have a
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/PI...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.

Dec 11 '06 #1
1 1496
"Dave" <on********@gmail.comwrote:
>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
Dec 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jangley | last post by:
Hi Tomcat seems to be completely ignoring any resource that I specify in an <error-page> directive in the web.xml. The same webapp works under 4.0. Is there a bug in 4.1 that I'm not aware of?...
1
by: John Altland | last post by:
Here is my basic problem. I have a form that executes a cpu instensive algorithm occupying the first thread. When the algorithm is executed another form pops up telling the user the progress that...
7
by: Dave | last post by:
Hello all, In the code below, I use a pointer to an object under construction. Is the usage below legal? I have come across similar code at work. It compiles, but I'm not sure it's really...
9
by: rskeples | last post by:
I write a small program. char *foo(void); char *a = "I like C"; int main(void) { if((strcmp(a,foo())) { printf("\n i like c"); } }
2
by: Tom | last post by:
Hi Everybod I want to update some controls in a form from another threads. I did it by passing the form to that thread and calling a delegate with Form1.Invoke, I want to have just one delegeate...
2
by: Meya-awe | last post by:
Anyone can tell me how to use control.Invoke or .BeginInvoke if i want to pass some day from a non-ui thread to a ui thread? Currently, i am using events into the UI module: private void...
12
by: Sankar | last post by:
Dear all, I am programming in Linux , wherein I need to know a couple of things. 1) Does an API exist that can copy file onto another file ( an API equivalent of 'cp') ? 2) Is there an API...
23
by: Thomas Due | last post by:
Hi, I have a class which monitors a TCP socket. This will on occasion raise an event which can be handled by a GUI. Now, I am aware of the if(InvokeRequire) { EventHandler d = new...
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.