Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 09:46 PM
Geoff Turner
Guest
 
Posts: n/a
Default VB and Callback functions

Hi all,
I am trying to write a simple DLL that calls back to the VB app that
called it in the first place.
Below is the code in the DLL
// start of code
FARPROC addr1 = NULL;
FARPROC addr2 = NULL;

extern "C" long _stdcall EXPORT Store (FARPROC a1, FARPROC a2)
{
addr1=a1;
addr2=a2;
return 0;
}

extern "C" long _stdcall EXPORT Execute (FARPROC addr)
{

long result;

if (addr1 == NULL)
return -1;
result = addr1();
result = addr2();
return result;
}

extern "C" long _stdcall EXPORT Execute2 (FARPROC addr , long value)
{
long result;
result = addr( value);
return result;
}
// end of code.

Now Store and Execute run OK.
Execute2 won't compile. I get the following error message:

"...Pointers.cpp(93) : error C2197: 'int (__stdcall *)(void)' : too many
actual parameters"
with the line 'result = addr(value);' producing the error.
What am I not doing correctly?

TIA
Geoff Turner.


  #2  
Old July 17th, 2005, 09:47 PM
MRe
Guest
 
Posts: n/a
Default Re: VB and Callback functions

> extern "C" long _stdcall EXPORT Execute2 (FARPROC addr , long value)[color=blue]
> {
> long result;
> result = addr( value);
> return result;
> }
> // end of code.
>
> Now Store and Execute run OK.
> Execute2 won't compile. I get the following error message:
>
> "...Pointers.cpp(93) : error C2197: 'int (__stdcall *)(void)' : too many
> actual parameters"
> with the line 'result = addr(value);' producing the error.
> What am I not doing correctly?[/color]


FARPROC is defined as...

typedef int (FAR WINAPI *FARPROC)();

....thus takes no parameters! Use something likes...

typedef long (WINAPI* FURTHERPROC)(long Value);

extern "C" long _stdcall EXPORT Execute2 (FURTHERPROC addr , long value)


Regards,
MRe


  #3  
Old July 17th, 2005, 09:47 PM
Geoff Turner
Guest
 
Posts: n/a
Default Re: VB and Callback functions


"MRe" <removethis_mre@dublin.ie> wrote in message
news:dwt7c.1832$qP2.6389@news.indigo.ie...[color=blue][color=green]
> > extern "C" long _stdcall EXPORT Execute2 (FARPROC addr , long value)
> > {
> > long result;
> > result = addr( value);
> > return result;
> > }
> > // end of code.
> >
> > Now Store and Execute run OK.
> > Execute2 won't compile. I get the following error message:
> >
> > "...Pointers.cpp(93) : error C2197: 'int (__stdcall *)(void)' : too many
> > actual parameters"
> > with the line 'result = addr(value);' producing the error.
> > What am I not doing correctly?[/color]
>
>
> FARPROC is defined as...
>
> typedef int (FAR WINAPI *FARPROC)();
>
> ...thus takes no parameters! Use something likes...
>
> typedef long (WINAPI* FURTHERPROC)(long Value);
>
> extern "C" long _stdcall EXPORT Execute2 (FURTHERPROC addr , long value)
>
>
> Regards,
> MRe
>
>[/color]

Thank you very much, that's just want I want.

Regards,
Geoff.


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles