msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Calling VB6 function from C

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise
Author Message
Anonymous



Joined: 04 Oct 2007
Posts: 20

PostPosted: Sun Sep 02, 2007 1:47 pm    Post subject: Calling VB6 function from C Reply with quote

I need to update a VB caption, with textual information - detailing
progress of processing being carried out in a C DLL.

Basically, I want my C function to be able to write messages back to VB,
which will then display the message in a label.

C prototype will be something like this:

#ifdef __cplusplus
extern "C" {
#endif

void writeGUIMessage(const char* msg);

#ifdef __cplusplus
};
#endif


How may I do this?

Archived from group: microsoft>public>vb>enterprise
Back to top
View user's profile Send private message
Ralph



Joined: 04 Oct 2007
Posts: 4148

PostPosted: Sun Sep 02, 2007 1:42 pm    Post subject: Re: Calling VB6 function from C Reply with quote

"Anonymous" wrote in message@bt.com...
> I need to update a VB caption, with textual information - detailing
> progress of processing being carried out in a C DLL.
>
> Basically, I want my C function to be able to write messages back to VB,
> which will then display the message in a label.
>
> C prototype will be something like this:
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> void writeGUIMessage(const char* msg);
>
> #ifdef __cplusplus
> };
> #endif
>
>
> How may I do this?

If you have your heart set on using Window Messages to communicate you may
find what follows poor advice. So if that's true you can stop reading now.

(By the way you are apparently using C++, not "C")

The easiest solution is to wrap your C++ code in an ActiveX component. If
using VC++ you can use ATL to simplify the process. Then expose a Event that
VB can use to update the Label.

In your VB code you would have...
Private WithEvents oJunk As MyDll
....
Private Sub oJunk_GUIMessage(ByRef sMessage As String)
Form1.Label1.Caption = sMessage
End Sub

I find using an ActiveX component far simpler that piddling around with
Hooks and such, and the ATL Wizard will manage most of the work for you.

-ralph

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group