# Visual Basic > Visual Basic 6 and Earlier >  how to call  a vb6 standalone exe module function from  c/c++ new thread-reg

## jsvenu

Dear Trick,

    I have gone thru all your examples in multithreading and interacted with you by which you clarified me how to use them.


We know that any c/c++ dll can interact with vb6 standalone exe thru module callback function using *addressof* operator.The c/c++ dll can export a function using .def file which takes callback function as parameter.
In the exported function we can execute the module function passed vb6 function pointer as parameter.The module function in this vb6 standalone exe can display for example a simple msgbox.

Can you show me a working  example of how to call  a vb6 standalone exe module function from exported function in which *new thread is created in c/c++ dll* so that it can also be *included in the code bank for which I shall be grateful to you*.

regards,
JSVenu

----------


## xiaoyao

Brothers worked hard, and it took a year and a half to see your speech again. I know you are not guilty and you are finally free. In fact, multithreading in VB6 is really hard, but we old VB developers don't want to give it up.
Multi-threading is realized in EXCEL VBA, multi-threading is realized in standard DLL, and multi-threading in ACTIVEX.EXE.

And VC++ calls the standard DLL written in VB6, and the VB function in it also needs to initialize the VB header, so it runs normally.

----------


## The trick

https://github.com/thetrik/VbTrickTh...StatusCallback
https://github.com/thetrik/VbTrickTh...Demos/Callback
https://github.com/thetrik/VbTrickTh...jectContextDll

----------


## jsvenu

Dear Trick,

   The sample requested by me is interaction between 
vb6 standard exe and c/c++ dll where the vb6 exe module function is executed by c/c++ dll exported function by accepting module function pointer as parameter.

The vb6 standard exe contains a module function which displays a simple msgbox.

The c/c++ dll can be either 

1.standard dll exporting a function which takes a function pointer as parameter so that it can accept vb6 standard exe module function as parameter and executes it in new thread created using CreateThread API.
or 
2.activex dll exporting a class member function which takes a function pointer as parameter so that it can accept vb6 standard exe module function as parameter and executes it in new thread created using CreateThread API.

None of the  examples mentioned has *c/c++ dll exporting function which tries to execute in new thread* the module function of vb6 standard exe.

regards,

JSVenu

----------


## The trick

Please read carefully. InternetStatusCallback is called from C/C++ dll in arbitrary thread.

----------


## jsvenu

> Please read carefully. InternetStatusCallback is called from C/C++ dll in arbitrary thread.


Dear Trick,

I have gone thru InternetStatusCallback folder of the link and I could not find c/c++ dll.The InternetStatusCallback  is vb6 standard exe project.

regards,
JSVenu

----------


## The trick

InternetCallback is called from wininet.dll.

----------


## jsvenu

> InternetCallback is called from wininet.dll.


Dear Trick,

I am sending the sampleproject.zip as attachment.It contains both c dll and vb exe projects.Only thing is we have to see that both c dll and vb6 exe are in same directory after building the projects.

The c dll exports callfunctionpointer function which accepts function pointer as parameter to which we give MyCallbackfunction  module function as parameter using addressof operator when we click on vb6 exe project displayed form callfunctionpointer button.The Callfunctionpointer function after accepting the vb module function creates a new thread using CreateThread API and tries to execute the vb6 callback.Wherever required the vb6 application uses  your modmultithreading2.bas.Here vb6 app *crashes * when I click on vb6 form button.

regards,
JSVenu

----------


## wqweto



----------


## The trick

> Dear Trick,
> 
> I am sending the sampleproject.zip as attachment.It contains both c dll and vb exe projects.Only thing is we have to see that both c dll and vb6 exe are in same directory after building the projects.
> 
> The c dll exports callfunctionpointer function which accepts function pointer as parameter to which we give MyCallbackfunction  module function as parameter using addressof operator when we click on vb6 exe project displayed form callfunctionpointer button.The Callfunctionpointer function after accepting the vb module function creates a new thread using CreateThread API and tries to execute the vb6 callback.Wherever required the vb6 application uses  your modmultithreading2.bas.Here vb6 app *crashes * when I click on vb6 form button.
> 
> regards,
> JSVenu


This is the last time i write - please read carefully the example. You just don't read the module description. When you'll have a trouble using the module description you can write here i'll help.

----------


## jsvenu

Dear Trick,
   I followed the *steps* as in *InternetCallback* sample and used
*InitCurrentThreadAndCallFunction* of *modmultithreading* module *properly* and finally resolved the crash problem.As usual *I thankyou very much with due respect for your sincere guidance and patience*.

regards,
JSVenu

----------


## xiaoyao

Any EXE or DLL written in VC++ can be called (standard DLL written in VB6, or exported function in standard EXE), but the export function in VB6 needs to initialize the vb header, otherwise MSGBOX cannot be used, or even windows api cannot be called , Such as findwindow

----------


## smkperu

> Dear Trick,
>    I followed the *steps* as in *InternetCallback* sample and used
> *InitCurrentThreadAndCallFunction* of *modmultithreading* module *properly* and finally resolved the crash problem.As usual *I thankyou very much with due respect for your sincere guidance and patience*.
> 
> regards,
> JSVenu


Hello jsvenu,

Can you send me the working code.

Thanks

----------


## jsvenu

Dear peru,

  code link attached

regards,
jsvenu

----------


## smkperu

Hello jsvenu,


Thanks

----------


## smkperu

Hello Trick,

Please clear space for sending PM.
Thanks

----------


## The trick

Stop spamming my inbox please! If you have a question please ask it in a new thread or an existing one.

----------


## smkperu

Hello Trick,

  but when I added __stdcall to async and added the following and tried in async.cpp without using .DEF file
#*pragma* comment (linker, "/EXPORT:async=_async@4")

extern "C" __declspec(dllexport) void *__stdcall* async(long  addr)

and  finally use async in vb6 std exe it *crashes* 

Thanks

----------


## The trick

> Hello Trick,
> 
>   but when I added __stdcall to async and added the following and tried in async.cpp without using .DEF file
> #*pragma* comment (linker, "/EXPORT:async=_async@4")
> 
> extern "C" __declspec(dllexport) void *__stdcall* async(long  addr)
> 
> and  finally use async in vb6 std exe it *crashes* 
> 
> Thanks


I doesn't work with p-code.

----------


## smkperu

Hello Trick,

  Ok. Now this *works* only  in native compiled code .
I have sent you a PM.

Thanks.

----------


## OptionBase1

> Hello jsvenu,
> 
> Can you send me the working code.
> 
> Thanks





> Dear peru,
> 
>   code link attached
> 
> regards,
> jsvenu





> Hello jsvenu,
> 
> 
> Thanks


LOL - we all know you operate both accounts, no need for the fake "handing off the question from one account to the other" posts.

----------

