URGENT: How to pass callback func as parameter?

Hi,

I have some generic (non MFC) class.

CSomeClass
{

SayHello() {
    return "Hello";
}

}

I however wish to be able to OVERRIDE this function with a custom function
in some other class like
CMyMFCApp.

This CMyMFCApp class is NOT subclassed from CSomeClass, so overriding that
function can not be done the same way as overriding base class functions
(simply redeclaring).

I am assuming I must set a call back function:

CMyMFCApp::Init()
{
CSomeClass sc;
sc.SetCallback(CMyMFCApp::MyCallback);
sc.SayHello();
}

CMyMFCApp::MyCallBack
{
   return "Wazzup?";
}

Now, I understand I can not just return strings in this fashion since the
pointer to it is no longer valid after function termination.. In reality my
function will be used to format numbers into strings. So the callback
function must receive a number (let's say a float value) and my callback
function must return a string formatted with a certain number of decimal
values.

I do not know how to define these call back functions.
Can someone help?

Lisa


0
no6060 (315)
10/14/2004 6:50:34 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
748 Views

Similar Articles

[PageSpeed] 30

Lisa Pearlson wrote:
> This CMyMFCApp class is NOT subclassed from CSomeClass, so overriding that
> function can not be done the same way as overriding base class functions
> (simply redeclaring).
> 
> I am assuming I must set a call back function:
> 
> CMyMFCApp::Init()
> {
> CSomeClass sc;
> sc.SetCallback(CMyMFCApp::MyCallback);
> sc.SayHello();
> }
> 
> CMyMFCApp::MyCallBack
> {
>    return "Wazzup?";
> }

You could:

1. make these callback functions static, or

2. if callback function can't be static: still use static callback but 
with additional parameter of void* that is a pointer to an object that 
the callback function will resolve:

CMyMFCApp::MyCallBack(void* pObject, [...])
{
    ((CMyMFCApp*)pObject)->DoStuff( [...] );
}

or

3. if you choose to drop the whole callback thing (mine favorite), use 
abstract class with one pure virtual function, that all classes (like 
CMyMFCApp) must inherit from.

> Now, I understand I can not just return strings in this fashion since the
> pointer to it is no longer valid after function termination.. In reality my

What's wrong with references to strings?

0
mac1 (347)
10/14/2004 7:52:25 AM
Reply:

Similar Artilces:

# (URGENT) NEW CHALLENGE AGAIN: HOW TO PRODUCE COMBINATIONS OF DIFFERENT RANDOM NUMBERS AND DO NOT FULLY SINGLE REPEATABLE AND WITH THE NUMBERS IN CRESCENT ORDER IN EXCEL 2003???
# NEW CHALLENGE AGAIN: HOW TO PRODUCE COMBINATIONS OF DIFFERENT RANDOM NUMBERS AND DO NOT FULLY SINGLE REPEATABLE AND WITH THE NUMBERS IN CRESCENT ORDER IN EXCEL 2003??? THIS SOLUTION ABOVE IS GREAT BUT DON'T HAVE THE 5+2 RANDOM NUMBERS AUTOMATICALLY SORTED IN CRESCENT ORDER. CHECK THIS FILE: http://cjoint.com/?kmqbqKuGZL THIS WORKS BUT THE NUMBERS ARE NOT SORTED AND I NEED SORT THEM IN CRESCENT ORDER IN A AUTOMATIC WAY (EX: {1,5,7,14,25, 1, 2} INSTEAD OF {5,1,7,25,14, 2, 1}) IF YOU CAN HELP, PLEASE HELP ME. I WILL BE GRATEFUL FOR YOUR HELP. THANKS FOR PRIESTING ATTENTION. Hi, Since...

why the error message error:illegal call of non-static member func
hello, I have written my own function to perform some operation.I call it from thread i have created in my program.But on compilation it gives the following error error:illegal call of non-static member function. why such an error comes?Does it have to do with calling the function from a thread?This is what i think?. When i declared the function as static it worked fine.... Can i know what was exactly going wrong and if i don't want it to be static what is the other solution? Please help sayu wrote: > hello, > I have written my own function to perform some op...

GETTING E MAILS . COMPUTER REQUESTS NAME AND PASS WORD.?????????
From: "Michael J. Strickland" <qualityservices2@verizon.net> Subject: Changing Report Printer - Access 2007 Date: Thursday, November 08, 2007 10:58 AM Anyone know how to change the printer associated with a report in Access 2007? Everytime I change the printer for a report, it reverts back to the Windows default printer. I know I can set the desired printer as the Windows default but I have hundreds of reports designed to use various different printers and doing this for each one is impossible. This behavior is new with Access 2007. Prior to this (Access 97, 2002, 2003 ......

Urgent - Calendar
Using Access2003. This db has a calendar popup form (thanks Allen Browne). The textbox for the date selected is named 'weekloaddate' and the default value is =Date()-Weekday(Date(),0)+1 so that when query is run it pulls weekly data from the Sunday of the current week. The query that was created to pull the weekly data was formatted for the week field as 'Format([Load Date],"ww")' with criteria of 'Format([Forms]![frmMain]![weekloaddate],"ww")' and another field for the year was formatted as 'Format([Load Date],"yy")' with c...

Multiple records for one parameter
I am in the Query editor window (design view) and I have on the top of the window all the tables with all the keys selected and working. In the bottom I have the fields with one field I wish to enter a parameter. Now I need to enter from one to several (Work order IDs) values. If I hard code in the line in the criteria field IN ("WO12345","WO12346","WO12347") this works, But if I try to make a parameter to have this entered in IN([Enter Work Order Ids]) then enter in the work orders when prompted it doesn't work. It will accept one work order id bu...

Pass-through queries not displaying in navigation window
I got a new pc and Office2007 at the same time. I have an access database that was created using Access2003 that had several pass-through queries in it. The pass-through queries no longer show up in my navigation window. If I run a query that calls one of the pass-queries, it will run but I cannot select the pass-through query to modify it or view the logic. How can I get the pass-through queries to show up in the navigation window? Are you showing "All Objects" and sorting them by "Object Type"? -- Lynn Trapp MCP, MOS, MCAS "owencn" wrote...

Creating custom Callback ...
Hi, How can I create custom callback functions and make them be called in the target application? Thanks, Hugo If I understand what you are getting at you will need to look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/ msdn_hooks32.asp Lots of sample code around if you search on hooks32 on google Andy Mortimer [MS] Please do not send email directly to this alias. This alias is for newsgroup purposes only ...

URGENT: Checkbox field in GridView ???
Hello. I develop an application in which I show records in a gridView. Then I'd like to select multiple records after which I click on a button and want to pass the list of selected records to an object. But I don't manage to select multiple records in the gridview !!! I tried by adding a checkboxfield but, apart from the column header, the actual checkbox for each record doesn't appear in the grid. Nor does anything happen when I click in that column So how? Apart from the checkboxfield, is there another way to select multiple records? thank you Chris ...

Move public folders between organisations : URGENT !!!
Hi all, I have to move public folders from an Exchange 2003 Server in organisation A to an Exchange 2003 Server in organisation B. I wonder how I can do that (the public folders mostly contain contacts). Cna you help ? This is very urgent, any help is appreciated !!!! Thanks a lot, Xavier Copy the PF to Outlook. Export Outlook to PST Import Outlook PST in new profile connected to new server Copy PF from Outlook into Public Folder tree. That's pretty much the migration method. PFMigrate might help here as well, but I haven't used that tool before, so my knowledge about it is...

Too Few Parameters, 1 expected
I'm getting the error too few paremeters, 1 expected with the code below. I'm getting the error at " Set rst3 = dbs.OpenRecordset(strSQL3)". Any help would be much appreciated On Error GoTo Err_cmdCreateRecords_Click Dim intResp As Integer Dim intCount As Integer If ReportDate = "" Or IsNull(ReportDate) Then MsgBox "Please enter a valid report date." ReportDate.SetFocus GoTo Exit_cmdCreateRecords_Click End If intResp = MsgBox("This function will add records for the reporting date specified. Do you wish to continue?", vbO...

Query ask for parameter value?
Hi, I biult a query from another one. When I run the query, Access keep ask the value of M and F. When I click OK I get the result that I want. Is there a way to tell Access not to display dialog asking for value of M and F? SELECT NumberOfCitizenSpeakingByQuarter.Quaters, Sum(NumberOfCitizenSpeakingByQuarter.[Meeting Observed]) AS [Meeting Observed], Sum(NumberOfCitizenSpeakingByQuarter.Male) AS M, Sum(NumberOfCitizenSpeakingByQuarter.Female) AS F, [M]/[Meeting Observed] AS [Avg Male], [F]/[Meeting Observed] AS [Avg Female] FROM NumberOfCitizenSpeakingByQuarter GROUP BY Nu...

Killed our CRM? by adding virtual directories? (urgent |-))
I searched here for a while, but could not find any hint on this: I orded our IT stuff to make a virtual directory on the IIS of CRM to use it as startpoint for some iframethings I wanted to do within CRM. No the CRM is dead - any idea what to do to get it back to life instead of backup? best regards Antonio I restarted IIS and now I can reach the CRM framework (windows opens, menu is there, but in the viewport there it says: Error Conact your Systemoperator to get further information No errorcode nothing else Any idea that could bring me back to my crm would be great :-) "A.K.B....

calling a C++ program from Excel 2000 and passing a result from C++ back to an excel spreadsheet
I have an excel spreadsheet and call a C++ program from a VBA macro using the command below. (I am not using visual C++ but a command line driven version, Borland C++ compiler) retval = Shell ("c:\options\options1.exe", vbNormalFocus) What I want to be able to do is to pass some of the values in my excel spreadhseet to the C++ program when calling it. There are 5 variables(spreadsheet cells) whose numerical values I want to pass across to the program. Once the C++ program has run I want to put a value that it caluculates in to a cell in my excel spreadsheet. Any help much...

Urgent: Distributing data into rows and columns
Please help me on how I could accomplish the following: Consider an example wherein I have just a single column having 200 rows. I would like the data to be evenly distributed into columns, eac having 50 rows. So, in this case it would be 40 columns, each having 50 rows. I woul sincerely appreciate any help. Thanks -- Message posted from http://www.ExcelForum.com Hi Have a look here: http://www.mvps.org/dmcritchie/excel/snakecol.htm -- Andy. "rajm >" <<rajm.163m0c@excelforum-nospam.com> wrote in message news:rajm.163m0c@excelforum-nospam.com... > Please help ...

Pesky Parameters
When I open a report I get prompted for two Parameters, FirstName and LastName. I looked everywhere for these variables; not seeing anything at all, but there must be something in there that’s causing this behavior. How can I find out where those pesky parameters are? Thanks! Ryan-- -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''. Look in: - the Sorting And Grouping pane - the Filter and Order By properties of the report - the Control Source of controls (you probably looked there.) If not found, examine the Record...

How to open Website with code, and enter search parameters?
I would like a button on a form to open a 3rd party website and automatically enter parameters into the .asp website to directly open up the search results. I think I need to use the Followhyperlink command, and I can get it to open the website, but the user needs to then enter the search paramters by hand and then hit the 'search button'. There has to be a way to automate the process, isn't there? I assume it is the 'extra info' parameter on the followhyperlink command but the help file isn't very useful. Thanks for any help, Get in touch with the webmaster hosti...

I'm trying to call outlook for a new mail passing the mailadress as a parameter
Hi, This maybe the worng place to ask this question, but still want to see if someone can answer me. I'm building a application and trying to call outlook from a program to create a new email. When I do this I want to include an email adres in the call. MSIMN.exe works to call outlook, but MSIMN.exe mveldhoen@quobell.nl has no extra effect. I can't seem to find out if there are parameters allowed in this call to outlook! Is there a syntax for the calling of outlook?? ...

How do I use same date parameters for different queries and report
I'm having the same problem as Gavelle described below. That is: I've followed the advice and set up a form to have my queries and reports pick the dates from the form. But the queries/reports are still asking me to enter the beginning and ending date parameters for each query/report. Also, when i set up the form it runs the query correctly. But when i try to run the query (or report based off the query) I only get a general parameter box stating Enter Parameter Value "forms!FORMNAME!StartDate and another for the end date. Everything in my query criteria is typed correc...

Urgent Help Plz
backup is failing. Running Veritas 9.1 ... fails with following error ... MS Information Store\First Storage Group\MailboxStore is corrupt file. This file cannto verify.Database or database element is corrupt. MSInformtion Store\First Storage Group\Logfiles is corrupt file. This file cannto verify. Database ordatabase element is corrupt. Help plz. Are your users experiencing any problems? Have you tried running NTBackup to see if this could be a Veritas issue as opposed to Exchange? Nue "WILDPACKET" <WILDPACKET@discussions.microsoft.com> wrote in message news:AED80965...

Query SQL server db with cell value parameter
I want to supply criteria value using a cell on the spreadsheet to contain a date. Can't seem to figure out how to do this. On the Connections - Properties - Definition dialog, "Parameters" is grayed out. ...

Move all replicas..urgent please help
Hi, When I click Move All Replicas, the replication is still not happening. I have kept it for 24 hours and am unable to delete the public folder. Any workaround to this? Your expertise needed please. pls guide. thanks in advance, Hi, See if this helps: http://support.microsoft.com/default.aspx?scid=kb;en-us;842273 Leif "Jack Dorson" <JackDorson@discussions.microsoft.com> wrote in message news:F4E9EED1-6A0D-417D-B70F-38D7E477071A@microsoft.com... > Hi, > > When I click Move All Replicas, the replication is still not happening. I > have kept it for 24 ho...

Passing Array to function
Hi All, I have defined the following variables type: Type XXX Var1 as double Var2 as double End Type Public XYZ(10) as XXX How can I pass the array XYZ to a function? Funcationname(XYZ ) doesn't seems like working Thanks. -- Gian Thanks SteAXA. I know what I did wrong. -- Gian "SteAXA" wrote: > I try this: > > Type XXX > Var1 As Double > Var2 As Double > End Type > > Public XYZ(10) As XXX > > Sub macro_1() > XYZ(0).Var1 = 11 > XYZ(0).Var2 = 12 > XYZ(1).Var1 = 21...

Passing arguments to procedures
There is something fundamental that I have failed to grasp about passing arguments to procedures. I have a form featuring a set of unbound controls displaying dates and the corresponding days of the week. (For some reason, the long-date format, on my computer, does not include the latter, as the documentation suggests it might, so it has to be separately calculated and displayed.) A default date is displayed in each control, on Form_Open. This can then be manually adjusted by a pair of ‘up’ and ‘down’ buttons associated with each day/date control pair. In the case of the control ‘St...

How to pass historical data from a legendary system to GP?
Hi, I need to send historical data(end of year) from AS/400 database to GP. Plz suggest me how cud i do that. Thanx in advance. Kiran. That depends on what type of data you want to import. Is it GL, AP, AR, Inventory, something else? Integration Manager, Table Import, and eConnect are the typical tools used to import data into GP. -- Charles Allen, MVP "Kiran" wrote: > Hi, > I need to send historical data(end of year) from AS/400 database to GP. > Plz suggest me how cud i do that. > > Thanx in advance. > Kiran. In addition to Charles's ...

Taking multiple parameters
I am running a query inside my macro that creates a worksheet full of some info. I want users to be able to take the results of one macro, and use it as arguments for another macro. So lets say I run 1 macro, I get 2 user ids as a result, say: 1, 2 Now I want to use these user ids as input parameters. Keep in mind these input parameters might vary. So how do I supply these as parameters to another macro? Pass the calculated or retreived values as parameters to the second macro: Sub Macro1() IDValue1 = "ID 123" IDValue2 = "ID 456" Macro2 IDValue1, IDValue2 End Sub Sub M...