question about AfxBeginThread

I'm really puzzled by the compiler message:
winckuView.cpp(108): error C2665: 'AfxBeginThread' : none 
of the 2 overloads can convert parameter 1 from type 'UINT 
(__thiscall CSerComm::* )(LPVOID)'

whereas I prototyped the function passed to AfxBeginThread 
like this:
UINT CSerComm::wakeInstrument(LPVOID pParam);

I'm calling AfxBeginThread like this (in a different 
source file):
AfxBeginThread(CSerComm::wakeInstrument, NULL);

What am I missing?
0
andre (4)
8/20/2003 10:40:07 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
667 Views

Similar Articles

[PageSpeed] 3

Sorry folks... I should have googled first. Turns out that 
the function wakeInstrument needs to be global.


>-----Original Message-----
>I'm really puzzled by the compiler message:
>winckuView.cpp(108): error C2665: 'AfxBeginThread' : none 
>of the 2 overloads can convert parameter 1 from 
type 'UINT 
>(__thiscall CSerComm::* )(LPVOID)'
>
>whereas I prototyped the function passed to 
AfxBeginThread 
>like this:
>UINT CSerComm::wakeInstrument(LPVOID pParam);
>
>I'm calling AfxBeginThread like this (in a different 
>source file):
>AfxBeginThread(CSerComm::wakeInstrument, NULL);
>
>What am I missing?
>.
>
0
andre (4)
8/20/2003 11:50:50 PM
Andre,

The wakeInstrument must be a *static* member of your class. The easiest way
to handle that limitation is to pass your class instance's <this> pointer in
as the LPVOID param. Then you can cast it back in the callback and delegate
back to the class instance.

Regards,
Mike

"Andre" <andre@wolk.org> wrote in message
news:03e601c3676c$0166d070$a601280a@phx.gbl...
> I'm really puzzled by the compiler message:
> winckuView.cpp(108): error C2665: 'AfxBeginThread' : none
> of the 2 overloads can convert parameter 1 from type 'UINT
> (__thiscall CSerComm::* )(LPVOID)'
>
> whereas I prototyped the function passed to AfxBeginThread
> like this:
> UINT CSerComm::wakeInstrument(LPVOID pParam);
>
> I'm calling AfxBeginThread like this (in a different
> source file):
> AfxBeginThread(CSerComm::wakeInstrument, NULL);
>
> What am I missing?




0
Michael
8/21/2003 1:39:24 AM
wakeInstrument has to be a static method.

Calling nonstatic methods is slightly more involved.

I (and others) just answered this same question recently.

Check old messages in the newsgroup.

Rufus

"Andre" <andre@wolk.org> wrote in message
news:03e601c3676c$0166d070$a601280a@phx.gbl...
> I'm really puzzled by the compiler message:
> winckuView.cpp(108): error C2665: 'AfxBeginThread' : none
> of the 2 overloads can convert parameter 1 from type 'UINT
> (__thiscall CSerComm::* )(LPVOID)'
>
> whereas I prototyped the function passed to AfxBeginThread
> like this:
> UINT CSerComm::wakeInstrument(LPVOID pParam);
>
> I'm calling AfxBeginThread like this (in a different
> source file):
> AfxBeginThread(CSerComm::wakeInstrument, NULL);
>
> What am I missing?


0
nospam2791 (369)
8/21/2003 1:53:09 AM
oops.  I made the same error by not reading the full
thread before answering.

"Andre" <andre@wolk.org> wrote in message
news:046e01c36775$e2a080f0$a601280a@phx.gbl...
> Sorry folks... I should have googled first. Turns out that
> the function wakeInstrument needs to be global.
>
>
> >-----Original Message-----
> >I'm really puzzled by the compiler message:
> >winckuView.cpp(108): error C2665: 'AfxBeginThread' : none
> >of the 2 overloads can convert parameter 1 from
> type 'UINT
> >(__thiscall CSerComm::* )(LPVOID)'
> >
> >whereas I prototyped the function passed to
> AfxBeginThread
> >like this:
> >UINT CSerComm::wakeInstrument(LPVOID pParam);
> >
> >I'm calling AfxBeginThread like this (in a different
> >source file):
> >AfxBeginThread(CSerComm::wakeInstrument, NULL);
> >
> >What am I missing?
> >.
> >


0
nospam2791 (369)
8/21/2003 1:54:05 AM
No, that is incorrect. It needs to be static. Certainly a global function meets this
requirement, but it is usually poor programming practice in C++ and MFC to create global
functions that are not needed. Typically, there is little value in making the function
global; declaring it as a static method of the class usually makes more sense. Note that
it does not need to be "global", it really needs to be declared at module level, and thus
can be declared "static", e.g.,
	static UINT MyThreadFunc(LPVOID p) { ... }
unless you have some reason to need it to be called from another module (which is
exceedingly rare). But it is better to declare it as a static class method; see my essay
on worker threads on my MVP Tips site.

					joe

On Wed, 20 Aug 2003 16:50:50 -0700, "Andre" <andre@wolk.org> wrote:

>Sorry folks... I should have googled first. Turns out that 
>the function wakeInstrument needs to be global.
>
>
>>-----Original Message-----
>>I'm really puzzled by the compiler message:
>>winckuView.cpp(108): error C2665: 'AfxBeginThread' : none 
>>of the 2 overloads can convert parameter 1 from 
>type 'UINT 
>>(__thiscall CSerComm::* )(LPVOID)'
>>
>>whereas I prototyped the function passed to 
>AfxBeginThread 
>>like this:
>>UINT CSerComm::wakeInstrument(LPVOID pParam);
>>
>>I'm calling AfxBeginThread like this (in a different 
>>source file):
>>AfxBeginThread(CSerComm::wakeInstrument, NULL);
>>
>>What am I missing?
>>.
>>

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)
8/21/2003 6:59:38 AM
I got it to work, i.e. the method is now a static member 
but I don't quite understand the declaration (please don't 
flame me ;-) :

include file:

static UINT doIt(LPVOID param);

class A
{
  static UINT doit(LPVOID param);
  ...
}

source file:

UINT A::doit(LPVOID param)
{
....
}


>-----Original Message-----
>Thanks for your suggestion - when I searched on google, 
it 
>wasn't directly clear to me that module scope would be ok 
>too (which of course is a lot cleaner in terms of 
>programming practice).
>I looked at your website (and added it to my favourites) 
>and found the workerthread page. I am not clear though on 
>how to declare the static member function.
>
>So, I ended up doing something like this:
>
>static UINT doIt(LPVOID param);
>
>class A
>{
>  B b;
>
>  ...
>
>}
>
>static UINT doIt(LPVOID pParam)
>{
>  // cast pParam back to class B object
>  B *pb = (B *) pParam;
>  // do something with pb
>
>  ...
>}
>
>void A::OnConnectWakeup()
>{ 
>  AfxBeginThread(doIt, &b); 
>}
>
>So there is no way to make doIt a static method of class 
>A? I tried it but then I got a compiler error: C2724 -
> 'static' should not be used on member functions defined 
>at file scope.
>
>
>>-----Original Message-----
>>No, that is incorrect. It needs to be static. Certainly 
a 
>global function meets this
>>requirement, but it is usually poor programming practice 
>in C++ and MFC to create global
>>functions that are not needed. Typically, there is 
little 
>value in making the function
>>global; declaring it as a static method of the class 
>usually makes more sense. Note that
>>it does not need to be "global", it really needs to be 
>declared at module level, and thus
>>can be declared "static", e.g.,
>>	static UINT MyThreadFunc(LPVOID p) { ... }
>>unless you have some reason to need it to be called from 
>another module (which is
>>exceedingly rare). But it is better to declare it as a 
>static class method; see my essay
>>on worker threads on my MVP Tips site.
>>
>>					joe
>>
>>On Wed, 20 Aug 2003 16:50:50 -0700, "Andre" 
><andre@wolk.org> wrote:
>>
>>>Sorry folks... I should have googled first. Turns out 
>that 
>>>the function wakeInstrument needs to be global.
>>>
>>>
>>>>-----Original Message-----
>>>>I'm really puzzled by the compiler message:
>>>>winckuView.cpp(108): error C2665: 'AfxBeginThread' : 
>none 
>>>>of the 2 overloads can convert parameter 1 from 
>>>type 'UINT 
>>>>(__thiscall CSerComm::* )(LPVOID)'
>>>>
>>>>whereas I prototyped the function passed to 
>>>AfxBeginThread 
>>>>like this:
>>>>UINT CSerComm::wakeInstrument(LPVOID pParam);
>>>>
>>>>I'm calling AfxBeginThread like this (in a different 
>>>>source file):
>>>>AfxBeginThread(CSerComm::wakeInstrument, NULL);
>>>>
>>>>What am I missing?
>>>>.
>>>>
>>
>>Joseph M. Newcomer [MVP]
>>email: newcomer@flounder.com
>>Web: http://www.flounder.com
>>MVP Tips: http://www.flounder.com/mvp_tips.htm
>>.
>>
>.
>
0
andre (4)
8/21/2003 7:45:49 PM
Reply:

Similar Artilces:

CStdioFile.ReadString question
Hello On a regular windows text file ReadString reads from a file until it sees 0D0A in hex terminating the line. In other files (for example UNIX text files and pdf files) a line is terminated only by 0D, but ReadString treats 0D not followed by 0A as normal character. What is the easiest workaround to this ? Peter ...

Exchange Server 5.5 IS Maintenance Question
Hi there, We have discovered that we need to allow the Information Store for Exchange Server 5.5 run and complete it's maintenance procedure. However, the problem is no matter how much time we give it, it still bogs down the server to the point of rendering it useless. For instance, we let it run from Friday at 7 pm to Sunday 5 pm and initiated our backup at 6 pm. When we came in Monday morning it was a total mess and the server had to be rebooted (something that cannot be afforded). My question is, there a way of segmenting the IS maintenance procedure or any other recommendations to...

Multi-Currency Question #2
Hello there, I would like to know why Customer balance is not adjusted automatically if I enter data with a different currency. For example if I enter 2000 in non-base currency as invoice with exchange rate of .0004 and pay it with exchange rate of .003, it shows that the customer still has balance of of 2 base. But I have paid all the non-base amount, but there are some Realized loss. Here is how I did: (All in in Non-Base Currency): Invoice: Qty Amount Total Currency Rate Base Amount(Calculated) 10 200 2000 .004 8 Pay...

Simple question #4
I'm relatively new to Excel and I want to creat a sheet for my expenses where I can enter a number in one column and have it subtracted from the above cell in the next column and so on, all the way down. I can do this by clicking on the bottom left of the cell and dragging it down but would like it to appear automatically. Sorry if that's not very clear. John In B1 enter the inital balance In A2 and on down enter your expenses In B2 enter: =IF(A2="","",B1-A2) and copy on down -- Gary''s Student - gsnu2007g "gtharwood@gmail.com" wrote: >...

CTabCtrl Question
Hi, all. I'm using a CTabCtrl (VC 6.0), and have a question on how to use it. Is there a way to add controls to specific tabs, so that each tabs associated controls are displayed if (and only if) that tab is selected? I know this is doable in something like VFP, but that's quite a horse of a different color. Or, do I just create controls (or dialogs?), hiding and and displaying them based upon the tab selection? If possible, a quick example of adding something like a button or text box would be extra helpful. Thanks in advance. Balboos I've never liked and used the CTab...

Basic Question
Hi all, I have a table called Companytbl with 2 fields: CompanyID (autonumber), CompanyName(text) On the form ( which related to a different table)I have company combobox. What exactly is the setup so on the combobox it will show the companyName and it will store in the table theCompanyID? TIA, Tom In news:%23Z%23x%23Q9JIHA.5928@TK2MSFTNGP05.phx.gbl, Tom <partner1973@yahoo.com> wrote: > Hi all, > > I have a table called Companytbl with 2 fields: CompanyID > (autonumber), CompanyName(text) > > On the form ( which related to a different table)I have company &...

Its a easy dumb question.
When i have formulas with there criteria not fullfilled, i get th "#N/A". How do i get that to go away -- comotoma ----------------------------------------------------------------------- comotoman's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2729 View this thread: http://www.excelforum.com/showthread.php?threadid=46828 comotoman Wrote: > When i have formulas with there criteria not fullfilled, i get th > "#N/A". How do i get that to go away? One way ... =IF(ISERROR(YOUR_FORMULA),\" \",YOUR_FORMULA will take care of th...

Case select question
Hi I have a case select code on my listbox. The listbox is called ReportID, I have an event procedure on dbl click. But when I dbl click the selection nothing happens. I have 2 columes of information that is shown in the list box, column 1 has report name, column 2 has report description. I put the report name in the case selection; from the table were reportID pulls information from did I write down the correct field information? Can anyone help me out? Private Sub ReportID_DblClick(Cancel As Integer) On Error GoTo handleErr Select Case Me!ReportID Case "Supply Plant Flour&...

ADMT question
When in the Security Translation Wizard of ADMT, concerning the user profiles security there is a "Replace" and an "Add". The docs for the ADMT push you to choose "Replace" with no real explaination. Would "replace" mean that what was there before would be "gone", meaing that you can never "go back" if something goes wrong? Wouldn't "Add" be the better choice if you are not confident that everything will go perfectly? -- Phillip Windell The views expressed, are my own and not those of my employer, ...

Question
We have two users in our organization that we wish to limit the size of mail they sent to each other but no one else. Does anyone know how to do this? Thanks in advance, Michael "Michael Henderson" <mhenderson@nospam.amerlink.com> wrote: >We have two users in our organization that we wish to limit the size of mail >they sent to each other but no one else. > >Does anyone know how to do this? I don't think you can. But why look for a technical fix for the problem when a simple warning to them should suffice? Would you chain them to their desks if you found ...

The question of redemption
Latest News - http://investorline.co.in/blogger/?q=3Daggregator Investor's Knowledge Analysis - http://investorline.co.in/blogs/news/?p=3D8= 50 Due diligence must for MF investors who invest in equity schemes. Retail investors in mutual funds (MFs) have displayed surprising maturity, staying invested in equity schemes despite the sharp fall of the stock markets from mid-January. However, it is too early to conclude that Indians have graduated to becoming long-term investors in equity and equity MFs. Experience shows that retail investors panic whenever markets go into a tailspin, cashin...

Data Migration Question???
Hi We have been using MSCRM for over a year now. Recently there has surfaced a need to import a large number of Account records to the existing database. However, I have read that the Data Migration Framework cannot be used for merges and is for a one off migration. Does this mean I cannot add records to CRM using the DMF if I have data in the database? Or is it just a case of not being able to add records that relate to existing data? Could anyone shed some light on this matter? Thanks in advance You can certainly use DMF to import more data into an existing MSCRM database. You cann...

VBA codes question
Hi, I just write down some VBA codes for an application. What I need is extract some data from a selected area by mouse left-button. So what should I do ? The most I concerned is how to get the Range object of the shadow area selected by mouse. Thanks. ...

CreateProcess question
Hi, I am trying to write an application that will launch a second application using CreateProcess... SECURITY_ATTRIBUTES sa; STARTUPINFO si; PROCESS_INFORMATION pi; ::ZeroMemory( &sa, sizeof(sa) ); sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; ::ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ::ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if ( !CreateProcess( NULL, "C:\\second_app.exe", &sa, &sa, TRUE, 0, NULL, "C:\\", &si, &pi ) ) { return; } ...

question on tables and queries
I've imported 2 tables from excel and ran a query against those two tables to determined the difference. This is something I would like to do each month. I would like to keep the same settings in my database, is there a way I can easily import/update the data in the new table without creating a new one each month? The query would stay the same as I'm comparing the same two files, but the the data will be changing every month. I don't know much about access and would like to know if there is an easier way of doing this besides creating a new table and query each month? I&...

Question on mixing MFC and Winform
We had some problems (I posted earlier about overlapping windows that may be transparent, draw order etc). Well we got the drawing working more or less but there is quite a bit of flicker. I was curious if we switched to WinFroms if perhaps things might work better. Our app is an unmanaged MFC app (we don't really use any of the Doc/View support). I've started reading and researching mixing of WinForms with MFC. I'm curious if I replace the CView with CWinFormsView and then create child windows of the type CWinFormsControl if this may help. But I'm not finding mu...

Sales Tax set-up question
I have a tax set up problem with RMS. I am using the "per customer" tax configuration because we ship products out of state and out of country. Here is the situation: Ontario (local) customers pay GST (federal) and PST (state/provincial) Rest of Canada pay GST only Outside Canada pay no tax However, in Ontario some products are still non-taxable (which is no problem) and some are GST only (which is a problem). Is there a way to accommodate all of this? Also, if I have a customer who is from out of province (with an out of province address in RMS) but who visits my store in Ont...

Wpf
I have a couple instances where I am using a set of data to define a window for testing purposes but I can't seem to find any place that really explains it. <Path Fill="#80D0E0FF" Stroke="Red" StrokeThickness="3" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M79,3L65,82 17,91 50,138 96,157 104,192 175,154 190,167 218,78 156,76 157,9 111,39z"/> In the Data attribute, I am trying to figure out what that means with the M's, Ls and z's. I have seen this shown ...

Challenging Question
Hello All, We are Exchange 5.5 SP4. I have a user who has a Palm Treo 600 smartphone. We are wirelessly synchronizing with Exchange over the internet using Goodlink software from Good Technology. Desktop client is Outlook 2003. All is working fine except the "opened" status is not being synchronized to his handheld. All other changes (new mail, deletes, calendar) are being synchronized, so it doesn't appear to be a connectivity issue. Any ideas or suggestions or requests for further information would be much appreciated. (the person having the issue is our company preside...

another question on printing invoices.
Thanks to a suggestion here, I was able to graph out the spaces on the invoices properly, but I ran into another snag, here's the situation: I am tryinhg to figure out a way to print invoices from an excell spreadsheet. The invoices are pre-formated with fields and logos and are on continuous paper that is fed into a dot matrix impact printer. It's NCR paper, an original and two copies. The rows of the spread sheet contain the data that needs to be in the invoice. Each row has customer information, ie, name, address, item bought, price per unit, number of units, sales tax, and t...

Conditional Format question #2
SG93IGNhbiBJIGNyZWF0ZSBhIGZvcm1hdCBmb3IgdGhlIGNlbGxzIHdoaWNoIGNvbnRhaW5zIGEg Y2VydGFpbiBzdWJzdHJpbmc/ > How can I create a format for the cells which contains a certain > substring? Select col A (A1 active), then apply the CF using Formula Is: =ISNUMBER(SEARCH("diesel fuel",A1)) Format to taste > ok out Replace SEARCH with FIND if you need it to be a stricter, case sensitive search -- Max Singapore http://savefile.com/projects/236895 Downloads:19,000, Files:362, Subscribers:62 xdemechanik --- Cells being in column A use Format>Conditional formatting with this ...

next question about taskbar
Ok...another question for you: I created the tray icon and now it works as intended. However, I had to have a parent window for it. Because it was simpler to understand I used a MFC modal dialog as the parent window. However, I don't want to see the dialog. My thought was that I would use the dialog as a splash screen and then hide it, leaving the tray icon as the only visible indicator of my program. But now I'm stuck and I can't figure out how to hide the dialog. The only thing I'm trying to accomplish is to have the tray icon running on it's own. I don't need the dia...

Install question
I'm installing Dynamics GP 10 for the first time. It installs perfectly but when I try and launch it, it starts the utility screen and I can't login. During the install it asked for the SQL Server database name, which I provided, but the utility only lists Dynamics GP as the database and sa as the login option. None of my known logins for the default SQL Server 2005 instance are working. Any ideas? for the utilities, you MUST use the sa user, as an initial installation, there are no DYNSA users etc.... So: 1. Make sure your ODBC is setup properly 2. Make sure you know your sa pa...

Linking images questions
I am preparing my 16 page newsletter for publication on offset printing. Most images in the newsletter are jpegs, a few are TIFFs. Once I insert all the images, I will convert them all to "Process Colors: CMYK" under the "Commercial Printing Option." I have a few questions about inserting images. What is the advantage of "linking" an image instead of "embedding" it for offset printing? Also, if I do link an image to a file, do I have to size the image exactly as it will appear in the newsletter before inserting it or can I insert the image and ...

how do i get my replys to my question?
fI'm a new user. I posted my question about Excel 2003 & went ofline. I loged in again but can't find a reply. You have not posted any other message in this newsgroup, at least not with the same name. -- Kind regards, Niek Otten "Yaron" <Yaron@discussions.microsoft.com> wrote in message news:E2006C73-01C4-4C80-96C4-7AE80B78D6DB@microsoft.com... > fI'm a new user. I posted my question about Excel 2003 & went ofline. I > loged > in again but can't find a reply. > > Yaron Have a look here for your first posting in .workshee...