|
But i did have a private static instance of Test class , and i use that to call the function pointer
|
|
|
|
|
You can't access instance members from a static method. Also the singleton implementation is wrong and your example doesn't make sense at all. Here is a modified version of your code which compiles fine.
class Test
{
private:
typedef void (Test::*SayHello)(char*);
SayHello sayHello;
Test()
{
sayHello = &Test::Say;
}
Test(const Test&);
Test& operator=(const Test&);
void Say(char* name)
{
cout<< "Hello " << name;
}
static void test()
{
Test* instance = Test::getInstance();
instance->FireSayHello("hello");
}
public:
void FireSayHello(char* message)
{
(*this.*sayHello)(message);
}
static Test* getInstance()
{
static Test instance;
return &instance;
}
};
Best wishes,
Navaneeth
|
|
|
|
|
Hello Everybody,
I am new to the windows 32 api and i am trying to use the win 3 api function CreateProcess.
I am simply trying to use this function to open the msn messanger process on my windows 7 pc, but i keep on getting a 0 exit code(failure). this is my code:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
void _tmain( )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( "c:\Program Files\Windows Live\Messenger\msnmsgr.exe", // module name (use command line)
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
the path c:\Program Files\Windows Live\Messenger\msnmsgr.exe is my msn messanger directory, but somehow i can get it to work.
Can someone please help me?
Thanks,
Nir Winter
|
|
|
|
|
only two things I can think of
1) try running [c:\Program Files\Windows Live\Messenger\msnmsgr.exe] from the command line from a dos/cmd prompt, see if that starts on its own, and/or double click it in explorer - hopefully this step will prove that its the right exe and doesnt need any parameters
2) I think the use of your module and command line args are slightly incorrect - I would repeat the [c:\Program Files\Windows Live\Messenger\msnmsgr.exe] in the commandline parameter of the createprocess api, so in effect the module name == the command line IN THIS CASE instead of the NULL you specified - if there were startup options [for example /s para-whatever] you would then end up with
if( !CreateProcess("c:\Program Files\Windows Live\Messenger\msnmsgr.exe", // module
"c:\Program Files\Windows Live\Messenger\msnmsgr.exe /s para-whatever", // commandline
NULL, //process handler
...
|
|
|
|
|
Don't you need two \ characters for literal character strings?
"c:\\Program Files\\Windows Live\\Messenger\\msnmsgr.exe",
|
|
|
|
|
I checked your code against mine and see the following differences:
- Creation flags. I use: normal_priority_class+CREATE_NEW_PROCESS_GROUP
- I use CreateProcess(NULL,"C:\Program files....". Thus turn the first 2 arguments.
- Try parent starting directory "c:\Program Files\Windows Live\Messenger". Or try to run something in the windows folder. Guess that the folder is not accessable. As mentioned try to run
it manually from the commandline.
- Set si.wShowWindow to SW_SHOWNORMAL
Does this help?
Rozis
|
|
|
|
|
Follow the suggestions by Garth J Lancaster and Chuck O'Toole .
In addition to those suggestions you also need to pass the command line in a modifiable array for the unicode version of CreateProcess .
Here is an excerpt from the documentation -
The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.
|
|
|
|
|
Hi,
I'll explain what I am trying to do with my project. I have created a client for a 3D world but when you click on the application the game launches but what I want is when you click on the application a login window appears so users can login to the project or create a new account with a new window.
Thanks
Andrew
Andrew McIntyre
|
|
|
|
|
MrMcIntyre wrote: but what I want is when you click on the application a login window appears so users can login to the project or create a new account with a new window.
And what is your doubt about?
It's just a dialog box with some text boxes and possibly static controls (and, maybe, one or two buttons...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
It's on C++ and I am having trouble creating code for it and to connect it to a database with user accounts and that would be fantatic to have it on the project.
Andrew McIntyre
|
|
|
|
|
I hope you are using Win32/MFC or windows for creating UI.
|
|
|
|
|
Visual Studio can create a skeleton dialog-based application for you, either a MFC project or a Win32 one(if you use MFC the task is somewhat simpler). As for connecting to the database, you've a lot of options (personally, I like ADO ), have a look at CodeProject's articles about [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Would it be easier if I pasted code onto here and I had one error but I don't think I have done right.
Andrew McIntyre
|
|
|
|
|
You may try.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Please excuse me if I get it wrong the first time but I will get use to it quickly. Here is the top part of the code and the area I put the CreateWindow Code.
<br />
<br />
#include <windows.h><br />
#include <windowsx.h><br />
#include <d3d9.h><br />
<br />
#pragma comment (lib, "d3d9.lib")<br />
<br />
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
<br />
void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void);
<br />
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);<br />
<br />
int WINAPI WinMain(HINSTANCE hInstance,<br />
HINSTANCE hPrevInstance,<br />
LPSTR lpCmdLine,<br />
int nCmdShow)<br />
{<br />
HWND hWnd;<br />
WNDCLASSEX wc;<br />
<br />
hWnd = CreateWindow(TEXT ("Login"),<br />
TEXT ("Login"),<br />
WS_OVERLAPPEDWINDOW,<br />
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,<br />
NULL,NULL,NULL,NULL);<br />
ShowWindow(hWnd,SW_SHOWNORMAL);<br />
UpdateWindow(hWnd);<br />
hdc = CreateDC(TEXT ("Design Results"), NULL, NULL, NULL);<br />
I need help with the textboxes, size and button for the dialog to be created. If I have got it wrong could you help me amend it.
Thank you.
Andrew McIntyre
|
|
|
|
|
In your WindowProc implementation,
you should handle WM_CREATE message and try create textboxes, button.
This[^] article may be helpful to you.
HTH
|
|
|
|
|
Can you show me how my code should look like and I will follow on and learn it for next time.
Andrew McIntyre
|
|
|
|
|
MrMcIntyre wrote: Can you show me how my code should look like and I will follow on and learn it for next time.
Why don't you learn it for this time?
|
|
|
|
|
As Chief Executive at iWorld, shouldn't your employees be handing this for you?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Tim Craig wrote: As Chief Executive at iWorld
Oops! Looks like somebody forgot to do their research...
Have a look at his website, you duffer. 
|
|
|
|
|
As a matter of fact, I did. That's why I made the comment. Hard to tell if he's being tounge in cheek or just seriously out of touch. For going to Europe's largest school, I would have hoped their English department was doing a better job.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Okay, fair point. Any chance I could have that "duffer" back - think I may need to assume that role for a little while.
Personally, I was left with the impression that it was a rather cheeky and informal tone on the site, though as you mention the spelling and grammar don't exactly put him in the queue for Pulitzer Prize winners. (not that I'll ever get one mind you)
|
|
|
|
|
Duffer? And I don't play golf at all. I infer that to you duffer probably means more like what dufus does to me. It did sound "cheeky" (and not the big butt meaning from this side of the pond) to me but I thought my reply could be taken either way depending on his meaning.
They do have a geek category for Pulitzer Prizes.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
You should handle WM_LBUTTONDOWN event for your client application.
After that you create a window using CreateWindow or use CMyDialog for logon
HTH
|
|
|
|
|
Is there any code floating around anywhere or a tutorial or someone who know how to create it anywhere just to help with this.
I am using Win32.
Andrew McIntyre
|
|
|
|