|
Hi,
I have a problem with function pointers in C++. As example;
class A
{
...
public:
double go(double (A::*f)(double, double));
double callMe(double, double);
void myFunc();
}
...
double A::go(double (A::*f)(double, double))
{
return f(1, 2); // for example
}
double A::callMe(double x, double y)
{
return x+y;
}
void A::myFunc()
{
go(&A::callMe);
}
But the compiler complains that A::f is not a function pointer?? I really can't se why. Any ideas
Thanks guys!
|
|
|
|
|
First off, I need to say that function pointers are yucky and should be avoided whenever possible.
I think the answer is:
double A::go(double (A::*f)(double, double))
{
return (*f)(1, 2); // for example
}
It's something so much nicer done with interfaces...
*sigh*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
This is untested, but change
double A::go(double (A::*f)(double, double))
{
return f(1, 2);
} to
double A::go(double (A::*f)(double, double))
{
return (this->*f)(1, 2);
} You can't call a non-static member function without specifying what the this object will be.
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
I have implemented an instance of IWebBrowser2 in my application and am using IDocHostUIHandler::GetHostInfo(DOCHOSTUIINFO* pInfo) to set various properties of the web browser such as no 3D border (DOCHOSTUIFLAG_NO3DBORDER) and no scroll bars (DOCHOSTUIFLAG_SCROLL_NO). I also wish to disable the running of scripts in my instance of the browser and have attempted to use DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE. The suppression of the 3D border and scroll bars is working perfectly but the suppression of scripts is not working. Here is my implementation of IDocHostUIHandler::GetHostInfo(DOCHOSTUIINFO* pInfo):
HRESULT FAR EXPORT ZBrowser::XDocHostUIHandler::GetHostInfo(DOCHOSTUIINFO* pInfo)
{
/*
DOCHOSTUIFLAG_DIALOG = 0x00000001,
DOCHOSTUIFLAG_DISABLE_HELP_MENU = 0x00000002,
DOCHOSTUIFLAG_NO3DBORDER = 0x00000004,
DOCHOSTUIFLAG_SCROLL_NO = 0x00000008,
DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = 0x00000010,
DOCHOSTUIFLAG_OPENNEWWIN = 0x00000020,
DOCHOSTUIFLAG_DISABLE_OFFSCREEN = 0x00000040,
DOCHOSTUIFLAG_FLAT_SCROLLBAR = 0x00000080,
DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = 0x00000100,
DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = 0x00000200,
DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = 0x00000400,
DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = 0x00000800,
DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = 0x00001000,
DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = 0x00002000,
DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = 0x00004000,
DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = 0x00010000,
DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = 0x00020000,
DOCHOSTUIFLAG_THEME = 0x00040000,
DOCHOSTUIFLAG_NOTHEME = 0x00080000,
DOCHOSTUIFLAG_NOPICS = 0x00100000
*/
pInfo->cbSize = sizeof(DOCHOSTUIINFO);
pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_SCROLL_NO | DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE;
pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;
return S_OK;
}
Any help on this would be greatly appreciated!
Thanks!
Peter Gorgia
peter.gorgia@tradeweb.com
|
|
|
|
|
I am creating a window at run-time, using this command:
CChildFrame2* pMDIChildWnd = new CChildFrame2;
pMDIChildWnd->Create(NULL, _T("My "), WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, rectDefault, NULL, NULL);
I've made a number of attempts to create a CCreateContext pContext, but have been unsuccessful. I think I might have to register some DocTemplate at initialization or something??
Please Help
A
|
|
|
|
|
I'm trying to create my threads, but when I go to compile this I get an error:
<br />
void CLAMsgSwDlg::StartAllThreads()<br />
{<br />
int nCount = m_lClientConn.GetItemCount();<br />
<br />
ThreadInfo *mythreadinfo = new ThreadInfo[nCount];<br />
for (int i = 0; i < nCount; i++)<br />
{<br />
mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0);<br />
mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1);<br />
<br />
CWinThread* pThread = new CWinThread[nCount];<br />
pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]);<br />
<br />
HANDLE* hThread = new HANDLE[nCount];<br />
hThread[i] = pThread->m_hThread;<br />
}<br />
}<br />
<br />
UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam)<br />
{<br />
m_sConnectSocket.SetParent(this);<br />
<br />
<br />
}<br />
<br />
Can some one tell me what I'm doing wrong here. i get an error "none of the 2 overloads can convert the first parameter"
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
You did not indicate what line was in error so I can only assume it was the AfxBeginThread() statement. Yes? If so, myThreadFunc() should be a static member, or a non-class function.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks David, I saw that in another program that I wrote a while back. After I made the function static, I received another error.
On the same call I get an error "operator =" function is not avaliable in CWinThread.
In the MSDN is says that it returns a pointer to the newly created object. Did I not setup my pointer right?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
OK, this may help you out. Firtly make the myThreadFunc static as David says.
Then if you alter the parameter class/struct to hold a pointer to the CLAMsgSwDlg class you can call the non-static member function and therefore other member elements.
Add the following to the ThreadInfo class/struct
CLAMsgSwDlg* thdParent;
Make the alterations in bold
void CLAMsgSwDlg::StartAllThreads()
{
int nCount = m_lClientConn.GetItemCount();
<p></p>
ThreadInfo *mythreadinfo = new ThreadInfo[nCount];
for (int i = 0; i < nCount; i++)
{
mythreadinfo[i].thdIPaddress = m_lClientConn.GetItemText(i, 0);
mythreadinfo[i].thdPort = m_lClientConn.GetItemText(i, 1);
mythreadinfo[i].thdParent = this;
<p></p>
CWinThread* pThread = new CWinThread[nCount];
pThread[i] = AfxBeginThread(myThreadFunc, &mythreadinfo[i]);
<p></p>
HANDLE* hThread = new HANDLE[nCount];
hThread[i] = pThread->m_hThread;
}
}
<p></p>
UINT CLAMsgSwDlg::myThreadFunc(LPVOID pParam)
{
ThreadInfo *threadinfo = reinterpret_cast<ThreadInfo*>(pParam);
ASSERT(theadinfo != NULL);
threadinfo->thdParent->DoThreadStuff();
}
<p></p>
void CLAMsgSwDlg::DoThreadStuff()
{
m_sConnectSocket.SetParent(this);
}
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
|
How to define current directory? Actually a directory from which program started. And a back side of this: how to define whether file exist in a specified path ?
|
|
|
|
|
Take a look at "GetModuleHandle" and "GetModuleFileName"
GetModuleHandle will return a handle to the currently running app.
Use the handle in GetModuleFileName to get the path of the module...or you app.
You can also use GetCurrentDirectory().
That should do it.
Hope this helps
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
I'm creating three to four socket client threads. Each one connecting to a different socket server.
At the creation of my threads I'm passing a pointer to a struct.
As each thread accesses this struct, will they see everything that the other threads see or will the struct be set in it own memory slot and only see data for that thread?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
All threads will see the same struct.
|
|
|
|
|
Im just stumped. Anyone know of a good article or demo
project which shows how to put a menu in a CDialog? I
just want to create a simple menu for a CDialog based
application.
Please, any response any one can give me will be
greatly appreciated.
Sincerely,
Danielle Brina (an overworked graduate student)
|
|
|
|
|
First create your menu in in the resource editor. if you have not added a menu then you will need to add one first.
After you've created your menu then in your dialog attach it. In .Net look in the properties menu for your dialog screen. In VS 6.0 right click on your dialog screen and choose properties. In the first tab you will see a drop down to choose your menu ID that you wich to use.
Hope this helps
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hi,
I need to crank out a quick, lightweight error reporting helper application, and would like to add a screenshot to it. I have a rough idea how I would do that, but do you know something "out of the box"?
Related: I'd love to save this to an e-mail file (including the image as attachment). Any lightweight helpers for that?
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
I want to put Skin of a PNG image on scrollbar of richedit control.how can i.
Learner always
|
|
|
|
|
When VS genereates a binary it writes full local path to pdb file as a string to it.
For example C:\Solution\Project\Release\Project.pdb
How to disable this and maybe other private information leackage?
|
|
|
|
|
What if you don't generate the PDB in the first place?
Then it might not write anything.
|
|
|
|
|
What do you by 'first place'?
Tried to switch to Debug and clean then back to Release and no success. String with path still presents even if pbd file doesn't exists.
|
|
|
|
|
This is what I meant...
Assuming Visual C++ 6.0 (You may have to search around for similar for VC 7.X or later...)
Open the Project Settings.
Make sure the 'Settings for' mentions your release build, typically 'Win32 Release'.
Go to the 'Link' tab.
Change the Category combobox to say 'Customize'
Make sure the 'Use Program Database' in NOT checked.
Change the Category combobox to say 'Debug'
Make sure that 'Debug Info' is NOT checked.
This will make your release EXE as much as possible without any symbols or line number information in it.
Make sure you do a Rebuild All after changing the settings.
Some companies build a release with enough symbolic information to use the PDB files to debug the release builds. Yours might have been set up or changed to be this way. The steps above will undo those changes.
|
|
|
|
|
Oh! No idea why I didn't find that menu before.
Thanks a lot! Now the binary is a little bit cleaner.
|
|
|
|
|
Hi
I'd like to know how get why LoadLibrary has failed. The error that I'd like to get is the unresolved symbol or dll that the loader cannot find. Like run a process using Explorer. If the .EXE depends of a DLL that do not exists or a function that is not exported by the DLL, the Explorer says the DLL file name or function name that could not be found.
|
|
|
|
|
I'm not sure if I understand you well...
If LoadLibrary fails, it returns NULL, otherwise it returns a handle to the dll module. To know why the function failed, call GetLastError.
Take a look at the MSDN, this might help you.
|
|
|
|