createwindow function in a vc++ dll

sanpippalin used Ask the Experts™
my question is can we create window(createwindowex) inside a dll(VC++) and call it from outside(VB).

I think It can be done by passing the handle from vb to VC++(dll).

can any one tell me exactly how to do it.

thanx in advance
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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.

Hope this helps.


Hi twalgrave
Thanx for such a quick response.

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