function pointer help!

I have a callback function

void __stdcall CallBackFunc(int, int,double);

And I need to have a pointer to it.

void (*CallBack)(int,int,double);

but the assignment doesn't work...

CallBack = CallBackFunc;

What am I doing wrong?

Thanks as usual!
Ron H. 


-----------------
www.Newsgroup-Binaries.com - *Completion*Retention*Speed*
Access your favorite newsgroups from home or on the road
-----------------
0
rnh1 (35)
11/13/2007 6:59:27 PM
vc.mfc 33608 articles. 0 followers. Follow

9 Replies
562 Views

Similar Articles

[PageSpeed] 18

Try this instead

void (_stdcall *CallBack)(int,int,double);

AliR.



"Ron H." <rnh@mmm.com> wrote in message 
news:4739f338$0$7517$8d2e0cab@news.newsgroup-binaries.com...
>I have a callback function
>
> void __stdcall CallBackFunc(int, int,double);
>
> And I need to have a pointer to it.
>
> void (*CallBack)(int,int,double);
>
> but the assignment doesn't work...
>
> CallBack = CallBackFunc;
>
> What am I doing wrong?
>
> Thanks as usual!
> Ron H.
>
> -----------------
> www.Newsgroup-Binaries.com - *Completion*Retention*Speed*
> Access your favorite newsgroups from home or on the road
> ----------------- 


0
AliR3470 (3236)
11/13/2007 7:31:17 PM
Have you tried making the pointer the same calling convention:

void __stdcall (*CallBack)(int,int,double);

Or, make the original a cdecl.

What error are you seeing?

Tom

"Ron H." <rnh@mmm.com> wrote in message 
news:4739f338$0$7517$8d2e0cab@news.newsgroup-binaries.com...
>I have a callback function
>
> void __stdcall CallBackFunc(int, int,double);
>
> And I need to have a pointer to it.
>
> void (*CallBack)(int,int,double);
>
> but the assignment doesn't work...
>
> CallBack = CallBackFunc;
>
> What am I doing wrong?
>
> Thanks as usual!
> Ron H.
>
> -----------------
> www.Newsgroup-Binaries.com - *Completion*Retention*Speed*
> Access your favorite newsgroups from home or on the road
> ----------------- 

0
tom.nospam (3240)
11/13/2007 7:33:09 PM
On Tue, 13 Nov 2007 12:59:27 -0600, "Ron H." <rnh@mmm.com> wrote:

>I have a callback function
>
>void __stdcall CallBackFunc(int, int,double);
>
>And I need to have a pointer to it.
>
>void (*CallBack)(int,int,double);
>
>but the assignment doesn't work...
>
>CallBack = CallBackFunc;
>
>What am I doing wrong?

You need to put the calling convention in the pointer declaration:

void (__stdcall *CallBack)(int,int,double);

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
11/13/2007 7:35:46 PM
Yeah, what they said... I typed it in too fast without trying it first 
<blush>

Tom

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message 
news:31vjj3hjshi4og6l9m6jfflkpcrjigam72@4ax.com...
> On Tue, 13 Nov 2007 12:59:27 -0600, "Ron H." <rnh@mmm.com> wrote:
>
>>I have a callback function
>>
>>void __stdcall CallBackFunc(int, int,double);
>>
>>And I need to have a pointer to it.
>>
>>void (*CallBack)(int,int,double);
>>
>>but the assignment doesn't work...
>>
>>CallBack = CallBackFunc;
>>
>>What am I doing wrong?
>
> You need to put the calling convention in the pointer declaration:
>
> void (__stdcall *CallBack)(int,int,double);
>
> -- 
> Doug Harrison
> Visual C++ MVP 

0
tom.nospam (3240)
11/13/2007 11:16:44 PM
On Tue, 13 Nov 2007 15:16:44 -0800, "Tom Serface"
<tom.nospam@camaswood.com> wrote:

>Yeah, what they said... I typed it in too fast without trying it first 
><blush>

I can never remember if the __stdcall goes before or after the star, so I
try it, get it wrong, and then correct it. I know that the star has to go
within the parens, and if it went to the right of the star, it would modify
the pointer. But a __stdcall pointer makes no sense. What we need is a
pointer to a __stdcall function, which means the star has to go on the
left. Maybe I'll remember it now, maybe not. :)

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
11/14/2007 12:41:18 AM
I can't get this function pointer to work! Here's the scoop: I am using a
third party I/O board. The manufacturer supplied a lib and header file with
the following typedef and cbEnableEvent function prototype:

 typedef void (__stdcall *EVENTCALLBACK)(int, unsigned, unsigned, void*);

int EXTCCONV cbEnableEvent(int BoardNum, unsigned EventType, unsigned Count,
     EVENTCALLBACK CallbackFunc, void *UserData);

I created a function to deal with the callback:

//the return void and input prameters are defined in the manual...
void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*)
{
}

So my challenge is to call cbEnableEvent with a pointer to CallHandler().

How about this?

EVENTCALLBACK pCallHandler;
pCallHandler = CallHandler;

The compiler complains with:

error C2440: '=' : cannot convert from 'void (__stdcall 
CMyProjectView::* )(int,unsigned int,unsigned int,void *)' to 
'EVENTCALLBACK'

        There is no context in which this conversion is possible



Any help will be greatly appreciated!!!

Ron H.







-----------------
www.Newsgroup-Binaries.com - *Completion*Retention*Speed*
Access your favorite newsgroups from home or on the road
-----------------
0
rnh1 (35)
11/14/2007 5:21:07 PM
I can't get this function pointer to work! Here's the scoop: I am using a
third party I/O board. The manufacturer supplied a lib and header file with
the following typedef and cbEnableEvent function prototype:

 typedef void (__stdcall *EVENTCALLBACK)(int, unsigned, unsigned, void*);

int EXTCCONV cbEnableEvent(int BoardNum, unsigned EventType, unsigned Count,
     EVENTCALLBACK CallbackFunc, void *UserData);

I created a function to deal with the callback:

//the return void and input prameters are defined in the manual...
void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*)
{
}

So my challenge is to call cbEnableEvent with a pointer to CallHandler().

How about this?

EVENTCALLBACK pCallHandler;
pCallHandler = CallHandler;

The compiler complains with:

error C2440: '=' : cannot convert from 'void (__stdcall
CMyProjectView::* )(int,unsigned int,unsigned int,void *)' to
'EVENTCALLBACK'

        There is no context in which this conversion is possible



Any help will be greatly appreciated!!!

Ron H.








-----------------
www.Newsgroup-Binaries.com - *Completion*Retention*Speed*
Access your favorite newsgroups from home or on the road
-----------------
0
rnh1 (35)
11/14/2007 5:24:14 PM
"Ron H." <rnh@mmm.com> wrote in message 
news:473b2e5f$0$7573$8d2e0cab@news.newsgroup-binaries.com...
>I can't get this function pointer to work! Here's the scoop: I am using a
> third party I/O board. The manufacturer supplied a lib and header file 
> with
> the following typedef and cbEnableEvent function prototype:
>
> typedef void (__stdcall *EVENTCALLBACK)(int, unsigned, unsigned, void*);
>
> int EXTCCONV cbEnableEvent(int BoardNum, unsigned EventType, unsigned 
> Count,
>     EVENTCALLBACK CallbackFunc, void *UserData);
>
> I created a function to deal with the callback:
>
> //the return void and input prameters are defined in the manual...
> void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*)
> {
> }
>
> So my challenge is to call cbEnableEvent with a pointer to CallHandler().
>
> How about this?
>
> EVENTCALLBACK pCallHandler;
> pCallHandler = CallHandler;
>
> The compiler complains with:
>
> error C2440: '=' : cannot convert from 'void (__stdcall
> CMyProjectView::* )(int,unsigned int,unsigned int,void *)' to
> 'EVENTCALLBACK'
>
>        There is no context in which this conversion is possible
>
>
>
> Any help will be greatly appreciated!!!


You are attempting to use a C++ member function as the callback, but the 
callback is defined in terms or C, not C++.  You can declare your C++ 
function as static, or simply make it a nonmember function.  The underlying 
problem is that C++ functions receive a hidden parameter, the 'this' 
pointer, so their signature is incompatible with C definitions.

Your static/global function will not be able to call other C++ member 
functions, but the usual solution to that is to pass your 'this' pointer in 
the void* UserData parameter.  Then in your callback function you can cast 
it back to an object pointer and call object functions with it.

-- 
Scott McPhillips [VC++ MVP] 

0
Scott
11/14/2007 6:37:54 PM
See below...
On Wed, 14 Nov 2007 11:21:07 -0600, "Ron H." <rnh@mmm.com> wrote:

>I can't get this function pointer to work! Here's the scoop: I am using a
>third party I/O board. The manufacturer supplied a lib and header file with
>the following typedef and cbEnableEvent function prototype:
>
> typedef void (__stdcall *EVENTCALLBACK)(int, unsigned, unsigned, void*);
>
>int EXTCCONV cbEnableEvent(int BoardNum, unsigned EventType, unsigned Count,
>     EVENTCALLBACK CallbackFunc, void *UserData);
>
>I created a function to deal with the callback:
>
>//the return void and input prameters are defined in the manual...
>void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*)
>{
>}
****
Note that you did not show the declaration of the function; it should be

static void EXTCCONV CallHandler(int, unsigned int, unsigned int, void *)

and in the absence of the definition of EXTTCONV we still have to guess about what you
mean here.  

The specification of the implementation

void MyProjectView::CallHandler(...etc...) {...}

would be identical if you declared it with or without the static qualifier.  So you have
shown us half of what we need to know.  However, I'm presuming you didn't know it should
be static, and if it isn't static, it won't compile, and the error you see is typical of
this kind of mistake.  Note that the function, once it is static, cannot access any member
values of the class.  Now, if the void* is a user-defined pointer, as it appears to be
inthe example above, you would use 'this' for the MyProjectView instance and in side you
could cast this LPVOID back to a (MyProjectView *) and be able to access the member
variables via that pointer.  See my essay on callback functions in MFC on my MVP Tips
site.
				joe

***** 
>
>So my challenge is to call cbEnableEvent with a pointer to CallHandler().
>
>How about this?
>
>EVENTCALLBACK pCallHandler;
>pCallHandler = CallHandler;
>
>The compiler complains with:
>
>error C2440: '=' : cannot convert from 'void (__stdcall 
>CMyProjectView::* )(int,unsigned int,unsigned int,void *)' to 
>'EVENTCALLBACK'
>
>        There is no context in which this conversion is possible
>
>
>
>Any help will be greatly appreciated!!!
>
>Ron H.
>
>
>
>
>
>
>
>-----------------
>www.Newsgroup-Binaries.com - *Completion*Retention*Speed*
>Access your favorite newsgroups from home or on the road
>-----------------
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
11/15/2007 1:37:55 AM
Reply:

Similar Artilces:

Help with expression
I have this expression that I entered in a experiment database and it works great. =DSum("[Amount]","YourTable","[TransactionType] =""Credit""")- NZ(DSum("[Amount]","YourTable","[Status] =""Cleared""")) I am now trying to modify it to work in my main database however I am having problems.I get a error message on the form and then it locks up while calculating =DSum("[Check Amount]","Transactions","[TransactionType] =""Credit""")- NZ(DSum("...

Address Labels
The situation: I work for a small business which has a large number of Excel wookboo files, each of which holds the details of a customer. Part of these details are - obviously - the name and address listin for that customer, with the name and each line of the address bein listed in seperate cells. The problem: The owner of the business has asked that I build up an Excel databas of every 2004-2005 customer (well over a thousand), which lists th name and address of each, in such a way that it can be printed directl onto sticky labels if necessary. Needless to say, trying to do this manua...

Help with creating invoice in other currency
I am looking to set up multi-currency invoicing so that I can create an invoice in Great Plains 7.50g3 in a currency (British Pounds) other than the functional currency (US Dollars). I believe I have multi-currency access set up properly, have currencies and exchange rates set up, have accounts set up to receive postings in multiple currencies, and the customer set up with a default currency of British Pounds. However, when I create an invoice, all the financial values are in US Dollars, and the Currency ID field is disabled. What is causing the Currency ID field to remain disabled? Th...

Help
Out of the blue today when I try to run Excel for Office97, I got "Required file MSO97.dll missing". So I looked at the PATH and copied MSO97.dll to a place in the path - "C:\windows\". Now I get the error message "Not enough memory to run Microsoft Excel". I have plenty of memory (almost 200MB). Word still works fine...but Access I get the same message. Previously Excel (and other Office programs) have run successfully. The only change is that recently i upgraded my Norton system works from version 2002 to 2004. My OS is windows 98. Of course I don'...

Carlos need help
setting up, just email me Using the same news.eternal.etc... "Kue2" <Kue2@hotmail.com> escribi� en el mensaje de noticias:i0fui7$69b$1@news.eternal-september.org... > setting up, just email me ...

Protect sheet help
I have a worksheet was setup to allow users to edit certain ranges when worksheet is protected. I deleted one of the ranges which users should not edit it anymore from the “Allow Users Edit Ranges…” window; however, the deleted range was editable even when the worksheet was protected. Just to experiment, I deleted all ranges from the “Allow Users Edit Ranges…” window, therefore, users should not be able to edit the entire worksheet when the worksheet is protected, and however, I was able to edit all ranges that were pervious setup to allow users to edit. Any ideas? Check that the cells are...

Chart Help -How ?
Hi, I'm a newbie with Excel & I am struggling to make this work. It's work related. I'm simply trying to show sales figures in a Pie-chart based upon the following information: Alex Frankie w/c 13/3/06 Calls made 45 70 No. not interested 10 10 No. interested 1 8 No. of call backs 34 52 Appointments made 0 1 But I can't work out how I'm going to show the legends but also including the 2 staff members. I'm sure somebody out there will have a better resolution. Thanks -- conks ----------------------------------------------------------------------...

Help! #11
When I print my contact list from outlook it says my name on top of each contact, which is ok. What I wanted to do was change the name so it said my company name. I cannot seem to find where the "profile name" is stored so that I can change it. I tried changing the email name, but that's not it. Email me please, as to I don't regulary come on here to post. Thanks in advance. TGS ...

Public folder replication help!!
how can i replicate on epublic folder structure to another on CURRENT Exchange server (not between some) thank U. I'm not sure what you're asking. Are you wanting to add a second public folder hierarchy on the same server and replicate your PFs between hierarchies on the same server? missy "Topper" <alexander.rodenkov@bix.ru> wrote in message news:uped6nP5DHA.2720@TK2MSFTNGP09.phx.gbl... > how can i replicate on epublic folder structure to another on CURRENT > Exchange server (not between some) > thank U. > > "Topper" <alexander.roden...

New to RMS: Having trouble setting up 2nd terminal.....HELP
We have an existing customer who has 1 server and 1 POS terminal. I have recently installed a 2nd terminal and am trying to match the settings and templates of the register 1 to the new register 2. The problem is with the on-screen keyboard. I've chosen the option to use the touchscreen keyboard in manager for register 2 and picked the template for the pre-configured keyboard layout; however, register 2 just refuses to display the template like register 1 does. I know ive got to be missing something. By the way, i forgot to mention that yes, i have enabled the touchscreen keyboard ...

help on adding a commandbar using VB com addin
Adding Commandbar to the New Mail message Inspector Window I was trying to add a new tool bar and also customize my new toolbar t automatically contain some commands programmatically. I wanna write COM add-in to OutLook that adds a new toolbar to the OutLook' Toolbar. This tool bar should apear only in new mail window. There are two commands(buttons) by name "Digitally sign Message" an "Encrypt Message Contents and Attachments". These are present in the Tools -> Customize -> Commands -> I categories select Standard -> on the Right side, if you scroll do...

Formula help! #2
hi all can someone help me where i have a row of numbers that go 0, 0, 0, 0, 0, 5, 10, 5 etc... from cells D2:K2 i want a formula to put in A2 that returns the first non- zero number, ie. it would return 5. it would also be useful to have a formula that returns which column the first non-zero number occurs in. any ideas? thanks JohnQ one way: First non-zero (array-entered: CTRL-SHIFT-ENTER or CMD-RETURN): =INDEX(rng,MATCH(TRUE,rng<>0,FALSE)) where rng is your range reference (e.g., D2:K2). Column the first-non-zero occurs in (also array-entered): =LEFT(ADDRESS(1,3+MA...

Online Publisher Help
Since the Office button does not appear in the Publisher 2007 interface, someone needs to change your "Save" file information in your online help for the Publisher SAVE function. I found it by trying to change the default Publisher file directory/folder, which apparently cannot be done (why was this removed for 2007 from earlier versions? It doesn't make sense since it save time!!!) ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in ...

Help needed on date()
Can anybody please tell me if, and how, I can use the date() funtion in excel for dates lying before 1900. The problem is that I'm trying to fill up columns with dates from a 19th century journal. thanks in advance D. Gerling Take a look at the following: http://j-walk.com/ss/excel/files/xdate.htm MRO "Delano Gerling" <delano@gerling.demon.nl> wrote in message news:vm99477u8k7mdc@corp.supernews.com... > Can anybody please tell me if, and how, I can use the date() funtion in > excel for dates lying before 1900. > > The problem is that I'm trying to f...

Urgent help request: How to find Journal Entry of Inventory Adjust
Hi folks, I have a urgent help request and question. How do I find out the Journal Entry number for an Inventory Adjustment transaction that did not post to G/L? You know when you post an Inventory Adjustment Batch, if you don't check the box "Post to General Ledger" the inventory adjustment will not post in G/L. So how do we find out what the Journal Entry number should have been? Here's the catch, don't have access to SQL Server, so we need a way to find out within GP. Is this possible? Please help...THANKS It sounds like you are trying to find out whether an in...

Method of calling a function where function name is stored in a variable or control
Is there a way to call a function (or sub for that matter) where the function/sub name is stored in a variable? For instance lets say I have a table that stores some function names. On a form I have a list box that displays the records in that table. For this example lets say they all accomplish similar things and all require the same numbef of arguments and none of them return a value. If Call were the right method to accomplis this it might look sometihng like this Dim lngArgument as Long lngArgument = 1234 Call Me.lstBox, lngArgument In this case Call would run the function...

Help with Exchange component of SBS2003
I have posted this to the Small Business Server forum and have not found any help, I thought I would try here... Okay, here is the problem....during an upgrade from SBS 2000 to SBS 2003, I experienced some sort of glitch that rendered the boot partition inaccessible. Since the partition could not be recovered through any method I tried, I decided to go ahead and do a clean install of SBS 2003 on that partition. SBS 2003 installed fine this time. Now the problem is the Exchange stores that were on the SBS 2000 server....the store database is still intact (I had it on a different pa...

Overriding virtual function Equals affecting static Equals...
Please observe the code snippet: namespace OverrideEquals { class Human { public string name {get;set;} public override bool Equals(object obj) { Human h = obj as Human; if (h is Human) { if (this.name == h.name) return true; else return false; } else { Console.Write("Not a human:"); return false; } } public override int GetHa...

Font and size help
In Excel 2007, I am updating a worksheet developed by someone else. I can't get a column of email addresses to display times new roman, 12. I have reset the page default, I have formatted just the column containing the email addresses and nothing seems to work. After entering an email address, it appears as ms sans serif, 10 with an underline (ie link address) I then change the individual cell to times ne roman, 12 and it is properly retained. Help appreciated. thanks Hi. This is due to your autocorrect options in Excel. To stop Excel taking over your formatting try the following:...

"ghost or blank" messages with date field of "none".....help?
using the ESEUTIL utility, we recently had to rebuild our message store because of a corrupted restore attempt. everything restored nicely...execpt now we have some users that have what seems to be blank messages. when outlook is opened, and messages are listed in the inbox or deleted items folder, these messages are blank except for the word "none" in the date field. they can not be accessed nor deleted. any ideas on how to resolve this issue?? thanks! On 26 Sep 2006 12:07:04 -0700, "kamor56" <kmorgan56@gmail.com> wrote: >using the ESEUTIL utility, we recentl...

AfxMessageBox not opening correct help topic?
In my application just after I call OpenDocumentFile on a doc template to instantiate a new doc/view frame window, I call AfxMessageBox under certain conditions. I add the MB_HELP style flag and pass an id for the help context. It seems however that when I hit the Help button, my application's help is opened to the section for the newly-created frame window and not the section I specified as the parameter in AfxMessageBox. I can't seem to figure out why. I put breakpoints all over the MFC code relating to help and none of them hit. In CWinApp::ShowAppMessageBox, either the owner frame&...

Date Error
Hello, Any help on the following matter would be greatly appreciated... I recently upgraded from Windows 95 to Windows 98 (yes, I realize the year is now 2005) and when I tried accessing one of my Excel spreadsheets, the dates were all whacky... For instance, what used to show as 05-Feb-2005 now appeared as "05<>Feb<>2005" (where <> is actually a small square). When I input a new date, it treats the entry as text as opposed to a date. This is even though I format the cell to recognize the entry as a date. Has anyone experience this before? I've been able...

Concerning Price Changing on Random Products. Please help!
It has been brought to my attention that certain products price have randomly changed. Certain products prices have either become lower or higher and there seems to be no correlation between products except for the fact that it affects only one price list. Does anyone have any ideas regarding this situation or has this happened to anyone else? THanks for your time. ...

Need help with TPX
I am trying to help a friend out with some her thermodynamics homework Some of her notes (supplied by a professor, but not written by him mention the use of a "TPX" add-in. I have done a number of searches online and see mention of TPX, but can't get it on Excel, and can't get any sort of TPX Add-in. If anyone has any advice, please let me know. This is reall frustrating. If it makes it easier I can post the notes that th professor has about the TPX information, but unless requested I don' want to make this post too long (the notes are maybe one page i length). Th...

can anyone help me finish this
This Works just fine as written it will copy to the current sheet just fine only I need it to Find the Last Sheet IN Workbook ("Master1") and copy to Range("J1:J140") of that sheet every time i run this This Macro The Sheet Name will Be different Thats why I need to have this routine find the Name. Im running windows xp sp2 with excel 2003 I will certanly be grateful to anyone that will bail me out as im firmly stuck Thanks Boyd Public Sub FindTheYeLLeR() Dim r As Range Dim i As Variant i = i i = i + 1 For Each i In Range("E244:E1000") If i...