Access a VC++ dll.

MPSINGH used Ask the Experts™
how can i create a window in a VC++ dll ,which would be called from a vb application.

I am developing a VC++ dll ,I have a function written in it.and within that function i am trying to create a window using createwindowex function.

I have used WC_GLOBALCLASS as style etc.please be precise i have done a lot to do it but all in vain.

A code snippet of dll would be appreciated very much .

please donot refer to the post of tvalgrave.
I have already seen the post of tvalgrave to mr. sanpippalin.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Are you trying to call the function in your DLL from VB? or access the window directly? ....

(I can help with the first, but not the other!)


Hi dave Riley

I am trying to call the function from VB.
You can call CreateWindowEX API directly from VB, you just need the VB declaration which is:

Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long

If you wrap this up in VB, VB still needs your function's declaration just like what is above.

But, let's say for the sake of argument that you want to make this as easy as possible for the VB developer.  Lets say you simply want VB to call a simple function in your C++ DLL that would automatically set up a window in a pre-defined format (all windows created the same way).  All VB needs back is the hWnd.  I'm assuming this is a regular DLL (with a WEP), not an ActiveX DLL. So in that case, create your C++ function with a long return value (or HWND as you might prefer).  Within your function, when you get the hWnd back from the API call, simply set it to the return value of your function.  So the VB declaration that would be needed to be used to call your C++ code would be something like:

Public Declare Function MYCreateWindowEXFunc Lib "MYDLLNAME" () As Long

It's that simple.

If you create an ActiveX DLL, VB simply needs to set a reference to it and then can use your function like any other COM object's function/property.

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- PAQ'd and points refunded

Please leave any comments here within the next seven days.
EE Cleanup Volunteer
Question closed and points not refunded

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial