473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Specifying __stdcall for function pointer as parameter

Ed
Suppose I want a function a pointer to which is going to
be passed to another function to use __stdcall conventions.
That is, I want the call to cbFunc() in tryCB3() to be compiled
for __stdcall calling conventions. What is the syntax?
I tried placing __stdcall in front of the (*cbFunc) but it is rejected
by the compiler.

long __stdcall tryCB3(long n, long (*cbFunc)(long m))
{
long r;
r = cbFunc(n); // call back
return r;
}

As background, the tryCB3() is going to be placed in a DLL
and called from Visual Basic, and the callback function is
going to be written in VB. The documentation indicates that
the call back function must use stdcall, but does not
tell be how to make the VC++ compiler make it that way.
The following is the VB code:
Private Declare Function tryCB3 Lib "SparkExUtilsDll.dll" _
(ByVal n As Long, ByVal theFunct As Any) As Long

Public Function theCBFunc3(ByVal m As Long) As Long
Debug.Print "In theCBFunc3"
theCBFunc3 = m * m
End Function

Public Function tryCBDrv3()
Dim n As Long
Dim q As Long
n = 2
q = tryCB3(2, AddressOf theCBFunc3)
Debug.Print "n= " & CStr(n)
Debug.Print "q= " & CStr(q)

End Function

When I step through tryCB3Drv it calls tryCB3, and then steps through
theCBFunc3, all working as expected, but then crashes with a C++
error dialog saying the ESP was not preserved through a function call etc.

Note that the it works without crashing if the callback function
has no arguments, so it must be some problem with the way VBA is setting
up the argument to theCBFunc3, vs. the way it's declared in C++.

Any ideas?

TIA

Ed
Jul 22 '05 #1
2 4144

"Ed" <Ja********@hotmail.com> wrote in message
news:88**************************@posting.google.c om...
Suppose I want a function a pointer to which is going to
be passed to another function to use __stdcall conventions.
That is, I want the call to cbFunc() in tryCB3() to be compiled
for __stdcall calling conventions. What is the syntax?
I tried placing __stdcall in front of the (*cbFunc) but it is rejected
by the compiler.

long __stdcall tryCB3(long n, long (*cbFunc)(long m))
{
long r;
r = cbFunc(n); // call back
return r;
}


__stdcall is not part of standard C++. You should ask questions like this on
a more appropriate newsgroup.

However the convention is actually the same as other declarations in C++.

__stdcall long (*cbFunc)(long m))

would mean that you are returning a __stdcall long, which is obviously
nonsense.

long (__stdcall *cbFunc)(long m))

means that you are pointing at a __stdcall function, which is what you want.
Remember C++ declarations are 'inside out'

If I got this wrong then apologies, but you really should ask Windows
programming questions on a Windows programming group because that's where
the Window programming experts hang out. Obvious really, try
news:comp.os.ms-windows.programmer.win32 next time.

john
Jul 22 '05 #2
Ja********@hotmail.com (Ed) wrote in message news:<88**************************@posting.google. com>...
Suppose I want a function a pointer to which is going to
be passed to another function to use __stdcall conventions.
That is, I want the call to cbFunc() in tryCB3() to be compiled
for __stdcall calling conventions. What is the syntax?
I tried placing __stdcall in front of the (*cbFunc) but it is rejected
by the compiler.

long __stdcall tryCB3(long n, long (*cbFunc)(long m))
{
long r;
r = cbFunc(n); // call back
return r;
}


This is system-specific, check your compiler's documentation
on __stdcall, it should have some examples, but
long __stdcall (*cbFunc)(long m)
should be correct. Make sure that the function prototype
matches the declaration too. Probably best would be something like:

typedef long __stdcall (*CallBackFunc)(long);
then
long __stdcall tryCB3(long n, CallBackFunc m)

If you still have trouble, try putting the _stdcall inside
the brackets (either before or after the *)
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: johny smith | last post by:
Can someone please explain to me the difference between these two: function1( const int a) function2( int const a) Both seemed to compile, but what is the difference between the two above....
2
by: lou zion | last post by:
hi all, i've got a class that takes a parameterless function pointer as a parameter. i want to store that function pointer in a variable and i'm trying to figure out the syntax. i came up with...
2
by: None | last post by:
Hello, 1. The prototype of function signal in signal.h: void (*signal(int sig, void (*func)(int)))(int); is some complex to me. Would you please explain it to me in detail with the C...
1
by: Eric Twietmeyer | last post by:
Hello, I am wondering how it is that all of the windows base dlls, like kernel32.dll specify that all of their functions are __stdcall and yet the exported names from the dll are not decorated...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
5
by: pauldepstein | last post by:
Hi all, I saw some code like this: unsigned short SomeFunc(unsigned short SomeNum, bool SomeBool, const SomeClass& SomeMem, bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.