|
You don't need a thread function to achieve this unless you want to do it that way .
See here[^]. You can make use of the scheduled task functionality provided from MS
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
modified on Wednesday, October 1, 2008 7:32 AM
|
|
|
|
|
Hello everyone,
In the poi command Windbg document it is mentioned below. My question is I want to find some samples to learn this command, but failed.
Does anyone have any ideas to make a simple sample. My confusion is after reading this document, I am not sure whether poi works similar to dereference address pointer for value or works similar to mov (no dereference), just a value copy.
--------------------
poi
Pointer-sized data from the specified address. The pointer size is 32 bits or 64 bits. In kernel debugging, this size is based on the processor of the target computer. In user-mode debugging on an Itanium-based computer, this size is 32 bits or 64 bits, depending on the target application. Therefore, poi is the best operator to use if you want pointer-sized data.
--------------------
thanks in advance,
George
|
|
|
|
|
Hai all,
I use two dialog boxes in my project which has a number of buttons with bitmaps loaded. I use F3 and F4 to navigate between the dialog boxes.
But while navigating after about 30 times the dialog shows "Debug Assertion". On debugging it goes to ASSERT(m_bitmap.m_hObjet != NULL).
In the PretranslateMessage()
Dailog1 *dlg1;
this->ShowWindow(SW_HIDE);
OnCancel();
dlg2->DoModal();
Dailog2 *dlg2;
this->ShowWindow(SW_HIDE);
OnCancel();
dlg1->DoModal();
Please any one help me.
Thanks and Regards
Bhanu
|
|
|
|
|
Talk about recursion. From the first dialog you're popping up the second, from the second you're popping up the first, from the first you're popping up the second, from the second you're popping up the first, from the first you're popping up the second, from the second you're popping up the first, from the first you're popping up the second, from the second you're popping up the first, from the first you're popping up the second................and so on, you get my point...
Eventually you will run out of stack space and that might be exactly what happens.
Have a look at your call stack when the assertion triggers.
The correct way to do this depends on what you're trying to do and how you want the two dialogs to interact. But I would recommend you to consider two modeless dialogs that you hide and show depending on F3/F4 keystrokes. Do not call DoModal() each time because that is your main problem right now combined with the recursion mentioned above.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
how to access object scope from one dialog to another dialog.How to call dialogs without using DoModal(),please help me .
Thanks and Regards,
Bhanu
|
|
|
|
|
bhanu_8509 wrote: how to access object scope from one dialog to another dialog.How to call dialogs without using DoModal()
You have to re-evaluate your design.
An application is supposed to have one main window that persists the entire life time of the application. What you're trying to do is change which window is the main window during execution and that suggests a design flaw.
I suggest you consider one of the following:
- Create an SDI application and select the CFormView class as view class.
You can create multiple CFormView derivatives and change between them with F3/F4 buttons, but the CMainFrame window object remains the main window of the application.
How to change between the views can be found by searching this site. - Continue to use a dialog based application, but create a tab control inside it.
The tab control can show different child dialogs and you can change between them using F3/F4 as you like.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Actually before call another window we totally close the window(use OnCancel() whenever we call OnCancel() memory was released including stack memory).After close this window only we call another window through(DoModal()).please advice me how to proceed.
Thanks and regards ,
Bhanu.
|
|
|
|
|
Hello everyone,
I am writing a C++ client to dynamically load a DLL and call its function, using LoadLibrary and GetProcAddress. In the C++ client, when executing statement -- "if(!StoreData(GetCurrentThreadId()))", after it returned, there is error message, any ideas?
(I showed along with the source codes for C++ client and the DLL itself)
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
DLL Client code:
#include <windows.h>
#include <stdio.h>
#define THREADCOUNT 1
#define DLL_NAME TEXT("testdll.dll")
VOID ErrorExit(LPSTR);
typedef BOOL(*StoreDataFp)(DWORD);
typedef BOOL (*GetDataFp)(DWORD*);
DWORD WINAPI ThreadFunc(VOID)
{
int i;
HMODULE hMod;
hMod = LoadLibrary("testdll.dll");
StoreDataFp StoreData = (StoreDataFp)GetProcAddress(hMod,"StoreData");
GetDataFp GetData = (GetDataFp)GetProcAddress(hMod, "GetData");
if(!StoreData(GetCurrentThreadId()))
ErrorExit("StoreData error");
for(i=0; i<5; i++)
{
DWORD dwOut;
if(!GetData(&dwOut))
ErrorExit("GetData error");
if( dwOut != GetCurrentThreadId())
printf("thread %d: data is incorrect (%d)\n", GetCurrentThreadId(), dwOut);
else printf("thread %d: data is correct\n", GetCurrentThreadId());
Sleep(0);
}
return 0;
}
int main(VOID)
{
DWORD IDThread;
HANDLE hThread[THREADCOUNT];
int i;
LoadLibrary(DLL_NAME);
for (i = 0; i < THREADCOUNT; i++)
{
hThread[i] = CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE) ThreadFunc,
NULL,
0,
&IDThread);
if (hThread[i] == NULL)
ErrorExit("CreateThread error\n");
}
WaitForMultipleObjects(THREADCOUNT, hThread, TRUE, INFINITE);
return 0;
}
VOID ErrorExit (LPSTR lpszMessage)
{
fprintf(stderr, "%s\n", lpszMessage);
ExitProcess(0);
}
DLL code:
#include <windows.h>
static DWORD dwTlsIndex;
BOOL WINAPI DllMain(HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
LPVOID lpvData;
BOOL fIgnore;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
return FALSE;
case DLL_THREAD_ATTACH:
lpvData = (LPVOID) LocalAlloc(LPTR, 256);
if (lpvData != NULL)
fIgnore = TlsSetValue(dwTlsIndex, lpvData);
break;
case DLL_THREAD_DETACH:
lpvData = TlsGetValue(dwTlsIndex);
if (lpvData != NULL)
LocalFree((HLOCAL) lpvData);
break;
case DLL_PROCESS_DETACH:
lpvData = TlsGetValue(dwTlsIndex);
if (lpvData != NULL)
LocalFree((HLOCAL) lpvData);
TlsFree(dwTlsIndex);
break;
default:
break;
}
return TRUE;
UNREFERENCED_PARAMETER(hinstDLL);
UNREFERENCED_PARAMETER(lpvReserved);
}
extern "C" __declspec(dllexport) BOOL __stdcall WINAPI StoreData(DWORD dw)
{
LPVOID lpvData;
DWORD * pData;
lpvData = TlsGetValue(dwTlsIndex);
if (lpvData == NULL)
{
lpvData = (LPVOID) LocalAlloc(LPTR, 256);
if (lpvData == NULL)
return FALSE;
if (!TlsSetValue(dwTlsIndex, lpvData))
return FALSE;
}
pData = (DWORD *) lpvData;
(*pData) = dw;
return TRUE;
}
extern "C" __declspec(dllexport) BOOL __stdcall WINAPI GetData(DWORD *pdw)
{
LPVOID lpvData;
DWORD * pData;
lpvData = TlsGetValue(dwTlsIndex);
if (lpvData == NULL)
return FALSE;
pData = (DWORD *) lpvData;
(*pdw) = (*pData);
return TRUE;
}
thanks in advance,
George
|
|
|
|
|
George_George wrote: extern "C" __declspec(dllexport) BOOL __stdcall WINAPI StoreData(DWORD dw)
extern "C" __declspec(dllexport) BOOL __stdcall WINAPI GetData(DWORD *pdw)
Why the declaration contains both __stdcall and WINAPI ?
WINAPI is already defined as __stdcall.
|
|
|
|
|
Hi Naveen,
You are correct. But I have tested that even if I removed WINAPI, the same error at the same line.
Any ideas?
regards,
George
|
|
|
|
|
George_George wrote: You are correct. But I have tested that even if I removed WINAPI, the same error at the same line.
because you're doing it wrong.
what did I say to you yesterday ?[^]
to Remove __stdcall declared before the return type (and that was the subject of your question yesterday!!!).
why do you still do it wrong ?
also, please edit your 1st post in this thread. the long line in the pre tag is breaking the formatting.
|
|
|
|
|
Hi toxcct,
I removed WINAPI, I think the effect should be the same, correct?
regards,
George
|
|
|
|
|
George_George wrote: I removed WINAPI, I think the effect should be the same, correct?
GOD NO !
the place of the calling convention is important !!!!
it shall be after the return type. so in brief, let WINAPI, and remove the other (which is moreover the same as WINAPI)
|
|
|
|
|
Hi toxcct,
I think the following two lines are the same. Seems you do not agree?
BTW: WINAPI is defined to be __stdcall.
extern "C" __declspec(dllexport) BOOL WINAPI StoreData(DWORD dw)
extern "C" __declspec(dllexport) BOOL __stdcall StoreData(DWORD dw)
regards,
George
|
|
|
|
|
George_George wrote: I think the following two lines are the same. Seems you do not agree?
yes, they are identical.
what I was complaining at was about the following 2 lines:
extern "C" __declspec(dllexport) __stdcall BOOL WINAPI StoreData(DWORD dw)
extern "C" __declspec(dllexport) BOOL WINAPI StoreData(DWORD dw)
|
|
|
|
|
Thanks toxcct,
I understand your point now.
regards,
George
|
|
|
|
|
Your dll function follows the standard calling convention (__stdcall) but you didn't add that in the typedef of the functions of your executable. Add the __stdcall in the typedef also, this should fix the problem (or the WINAPI, which is the same thing).
|
|
|
|
|
Hi Cedric,
Using __stdcall in function pointer typdef will cause compile error. Here it is. Any ideas?
typedef BOOL __stdcall (*StoreDataFp)(DWORD);
1>d:\visual studio 2008\projects\testdll\testdllclient\main.cpp(11) : error C2059: syntax error : '('
1>d:\visual studio 2008\projects\testdll\testdllclient\main.cpp(21) : error C2065: 'StoreDataFp' : undeclared identifier
1>d:\visual studio 2008\projects\testdll\testdllclient\main.cpp(21) : error C2146: syntax error : missing ';' before identifier 'StoreData'
1>d:\visual studio 2008\projects\testdll\testdllclient\main.cpp(21) : error C2065: 'StoreData' : undeclared identifier
1>d:\visual studio 2008\projects\testdll\testdllclient\main.cpp(21) : error C2065: 'StoreDataFp' : undeclared identifier
1>d:\visual studio 2008\projects\testdll\testdllclient\main.cpp(21) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
1>d:\visual studio 2008\projects\testdll\testdllclient\main.cpp(25) : error C3861: 'StoreData': identifier not found
regards,
George
|
|
|
|
|
You have to put it inside the parenthesis. See here[^] for example.
|
|
|
|
|
Thanks Cedric,
I have tried your solution works. It is good to learn from you that we also need calling convention for function pointer definition.
regards,
George
|
|
|
|
|
I suggest you read a bit more about calling conventions to understand what it is exactly (basically, this defines who, of the caller or the callee, will clean the stack after the function terminates). By default, C++ uses a __cdecl calling convention. In your dll, you explicitely stated that your functions should follow the __stdcall convention. If in your executable (in your typedef), you don't specify that the function uses a __stdcall calling convention, there's no way for your executable to know that, so it will uses the __cdecl as usual, thus your crash.
|
|
|
|
|
Thanks for your advice, Cédric!
I did not know for function pointer, we also need to define calling convention as well.
regards,
George
|
|
|
|
|
In fact it is logical when you think a bit about it. Your function is in your dll and you use it by calling LoadLibrary and GetProcAddress. To load the function you use a typedef in your exe to specify how the function looks like, this is the only way for your exe to know the function. So, if you don't specify on the function typedef that the function uses a __stdcall calling convention, the exe has no way of knowing that information.
|
|
|
|
|
Thanks Cédric,
Your description is very reasonable.
regards,
George
|
|
|
|
|
Hi Experts,
How can I traverse System Volume Information folder?
I also got the solution "You have to take ownership of the directory and its objects before you can enumerate them."
But how can I do that?
|
|
|
|
|