|
Hi Everybody,
I have problem with global functions in VC++.Net, is simply
add a global function in my project like:
UINT MyThreadProc(LPVOID pParam)
{
...
return 0;
}
and then when i want to call it for example when pressing abutton : AfxBeginThread(MyThreadProc,0) , i get an error :
c:...: error C2065: 'MyThreadProc' : undeclared identifier
can anyone help ?
Regards
Giorgi Moniava
|
|
|
|
|
When the compiler compiles a cpp file it starts at the top and works it's way down. If it finds an identifier (variable or function) that was not declared in a line above the current line it will generate this error. What you have to do is either insert a forward declaration of your function at the top of your cpp file (header files are a good way to do this), or move your function to a point in the file before the line that caused the error.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
I want to restart the process. At first i created the process using createprocess() and then suspend it using suspendthread() and then i saved its state and information about it e.g. baseadress, context, state e.t.c in a binary file, after that i terminate it. Now i want to recreate it using its suspended state information. Pliz help me about this because i tried to use the functions below but the process doesnt restart again or atleast how to recreate a process using information from a previous saved information.
<br />
case 5:
<br />
SuspendThread(pi.hThread);
printf("\nThe thread of ID: %d",pi.dwProcessId);<br />
printf(" has been suspended!\n");<br />
GetLastError();<br />
<br />
GetThreadContext(<br />
hProcess,
lpContext
);<br />
GetLastError();<br />
<br />
regnum = 0;<br />
base = 0;<br />
fp = fopen("checkpoint.bin","w");<br />
if( fp )<br />
<br />
while (base < sinfo.lpMaximumApplicationAddress) <br />
<br />
{<br />
VirtualQueryEx(hProcess, base, &mbi, sizeof(mbi));<br />
<br />
if (mbi.State == MEM_COMMIT)<br />
state = "Used";<br />
else if (mbi.State == MEM_FREE)<br />
state = "Free";<br />
else if (mbi.State == MEM_RESERVE)<br />
state = "Reserved";<br />
else<br />
state = "Unknown";<br />
<br />
<br />
printf("\nREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \<br />
Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, mbi.AllocationBase, \<br />
mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type);<br />
<br />
base = (LPVOID)((unsigned long)mbi.BaseAddress + (unsigned long)mbi.RegionSize);<br />
<br />
regnum++;<br />
<br />
<br />
fprintf(fp,"\nREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \<br />
Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, \<br />
mbi.AllocationBase, mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type); <br />
<br />
}
<br />
Sleep(3600);<br />
<br />
TerminateProcess(pi.hProcess, 0);<br />
<br />
break;<br />
<br />
case 6:
lpBaseAddress = 0;<br />
hProcess = mbi.BaseAddress;<br />
SetThreadContext( <br />
hThread, <br />
lpContext <br />
);<br />
OpenThreadToken(<br />
ThreadHandle,
DesiredAccess,
OpenAsSelf,
TokenHandle
);<br />
<br />
WriteProcessMemory(<br />
hProcess,
lpBaseAddress,
lpBuffer,
nSize,
lpNumberOfBytesWritten
);<br />
<br />
ResumeThread(hThread);
GetLastError();<br />
<br />
break;<br />
oam
|
|
|
|
|
You can't do what you are attempting. Process management is up to the operating system. Does the comment "restarting the process in the other machine " mean that you are attempting to move processes from one machine to another? That absolutely won't work either.
You need to design your application so that it can save its state to a file when it exits, and restore its state from a file when it starts up.
Software Zen: delete this;
|
|
|
|
|
When it starts up? Do you mean when i re-run it again.
My application automatically save the state of a process when i suspend it.
But now i want to use this state to restart/recreate this process again, e.g. like if i can send this information to another computer.
It was done before but this was in unix.
Check this:
Restoring[^]
oam
|
|
|
|
|
mpapeo wrote:
When it starts up? Do you mean when i re-run it again.
Yes.
mpapeo wrote:
My application automatically save the state of a process when i suspend it.
This won't work under Windows. There are too many external factors involved that you can't control.
mpapeo wrote:
It was done before but this was in unix.
I thought that might be the case.
mpapeo wrote:
Check this:
Restoring[^]
I skimmed through the article. They are describing the approach I recommended. The application saves its state in a file, and then can reload that file when it runs again. Saving the process memory space and restoring it won't work (especially moving it from one machine to another) because the contents of the memory space includes items that you can't control.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote:
I skimmed through the article. They are describing the approach I recommended. The application saves its state in a file, and then can reload that file when it runs again. Saving the process memory space and restoring it won't work (especially moving it from one machine to another) because the contents of the memory space includes items that you can't control.
so do you mean it can be difficult in windows to implement this
Gary R. Wheeler wrote:
mpapeo wrote:
When it starts up? Do you mean when i re-run it again.
Yes.
Well if that is the case then it will be part of what i want. Because the process i am creating prints numbers on the screen. But i suspend it and save its state and then when i re-run it it then continues to print numbers from where it left i knew i will be moving to somewhere in my research.
You can give you email so that i sed you the code
oam
|
|
|
|
|
Hi all,
I got a AES impelmentation code in VC++ and have some doubts, which I cannot sort out.
Will you plssssssssss let me know if u are familiar with both the AES algorithm and VC++.
So that I can forward my doubts along with the programme.
Thx...
vendy2k4
|
|
|
|
|
My main question is, I need to be able to get the filesize of a file greater than 4 gb. I use Visual C++ 6.0, and I am most comfortable with fstream. The fstream pointers are only 32 bit however. Is there another function I can use to get the filesize?
Two secondary questions are, one problem I have is sometimes the autocomplete/member listing stops working. I have to save everything, close, and reopen VC++ to get them to work again. Is there another way to fix it? And sometimes during compiling it will just stop before linking. I'll press the stop build button and it won't stop, I have to save everything and end the process via Task Manager. Is there a better way to fix that?
Thanks in advance for any help.
|
|
|
|
|
Master Shake 144 wrote:
Is there another function I can use to get the filesize?
I know of two: GetFileSizeEx() and CFile::SeekToEnd() (requires opening the file).
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
GetFileSizeEx only works on W2K+.
CFile::SeekToEnd() returns a 32bit value in MFC 6, a 64 bit value in MFC 7
_lseeki64 works on 9x and MFC6
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
|
|
int main(int argc, char* argv[])
{
switch(argc)
{
case 1:
break;
case 2:
if(argv[1] == "-help")
{
cout << "Help" << endl;
}
break;
default:
break;
}
return 0;
}
If the program in this case is named "prog.exe", when I type "prog.exe -help" into the command line, my understanding is that "Help" should be printed into the command line window. Any ideas as to why it isn't working?
Also, if there is a better way to check to see which program parameters have been passed in than the way I am trying to do so, please let me know. I am open to suggestions.
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
|
|
|
|
|
One solution is strcmp().
Kuphryn
|
|
|
|
|
Thanks for the help!
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
|
|
|
|
|
bneacetp wrote:
if(argv[1] == "-help")
Herein lies your problem.
|
|
|
|
|
Yep. I agree. I changed
if(argv[1] == "-help") to
if(strcmp(argv[1], "-help") == 0) and that solved the problem.
Thanks for taking the time to point that out.
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
|
|
|
|
|
Unless you REALLY need to look exactly for "-help" I would recommend a case insensitive string comparison. Not all users rememebr you want all lower case for command line arguments, for example - see stricmp
|
|
|
|
|
Alright. That certainly is a good suggestion. Thanks.
I believe I will make that change. Thanks for taking the time to let me know about the stricmp() function.
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
|
|
|
|
|
how do i create a PE explorer or a resource hacker?
|
|
|
|
|
There is a very small-scale one on MSDN, and a much better one here at CP. Have you tried Googling?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi everyone!
I'm trying to send VK_RCONTROL to an application by unsing the SendInput method.
Does anyone know how to do this?
void sendChar(BYTE c){
INPUT input[2] = {0};
input[0].type = input[1].type = INPUT_KEYBOARD;
input[0].ki.wVk = input[1].ki.wVk = c;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
::SendInput(sizeof(input) / sizeof(INPUT), input, sizeof(INPUT));
}
//Doesn't work
sendChar(VK_RCONTROL);
|
|
|
|
|
Can you try it with the VK_CONTROL to see if it works?
I found this comment in WINUSER.H, which makes me suspicious that the VK_RCONTROL might not work ever.
* VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
* Used only as parameters to GetAsyncKeyState() and GetKeyState().
* No other API or message will distinguish left and right keys in this way.
|
|
|
|
|
Thanks for the response!
I've tried VK_CONTROL, but it will act as the left control button.
Since the program I'm trying to send right control to is making a destinction between right and left, there has to be a way to send right control. (read hack)
/Peter
|
|
|
|