|
Randor's correct in the overall behaviour but not some of the details. The compiler normally generates direct CALL instructions to call code not in the current translation unit. It leaves a direction to the linker to fill in the necessary value with the address of the corresponding symbol at link time.
The import library that you link with is what contains the JMP instructions, which look like:
MyFunc:
JMP __imp__MyFunc That's the 'import thunk'. There's one thunk per routine in the DLL that this is the import library for.
If you specify __declspec(dllimport) , the compiler instead generates an indirect call instruction and the instruction to the linker references __imp__MyFunc rather than MyFunc . When the call is made, instead of the instruction pointer going first to the thunk, then to the function itself, it goes directly to the function.
The symbol __imp__MyFunc itself actually points to a pointer-sized value in the Import Address Table which the loader (part of the OS) writes the actual address of the function to at load time.
Also included in the import library is the full Import Address Table for the DLL, which contributes to building up the IAT in the executable itself.
For more, see http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/[^].
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
Thanks Mike,
Two more comments,
1.
For the less-optimized form (if user does not specify dllimport),
jmp DWORD PTR __imp_func1
is treated as implementation function func1?
2.
How did the linker know the address of IAT table itself? It is some hard coded value or always have the same value in every PE file?
regards,
George
|
|
|
|
|
Hi friends
How to hide mouse pointer in MFC
thanks in advance
-RisKhan-
|
|
|
|
|
Nothing to do with MFC, but still correct:
SetCursor (NULL);
Be warned though - this is prone to problems. If your message pump is still working, then you may get messages like WM_SETCURSOR , which could cause another part of your program to put the cursor back to something useful again.
And if you can cure that, you can't stop other programs setting the cursor when you go over them. And it would be a TERRIBLE thing if you could.
But if you're full screen, and well written. you can get rid of the cursor. Or if you have no mouse, and therefore no mouse movement!
Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
|
|
|
|
|
int ShowCursor(
BOOL bShow
);
|
|
|
|
|
I connect to some FTP server and put on him some file.
I see that the return code of the PutFile is 1 ( that mean that all OK ) but when i try to catch the "StatusCallback" i never get the dwInternetStatus that say INTERNET_STATUS_REQUEST_COMPLETE.
When i check the FTP Server i see that my file is store fine and its look like everything is fine.
But i still except from the server to return me the flag INTERNET_STATUS_REQUEST_COMPLETE.
Beside this - i also don't understand why the call of the function OnStatusCallback is not asynchronous call.
My code:
<br />
class CMyInternetSession : public CInternetSession<br />
{<br />
public:<br />
CMyInternetSession(LPCTSTR pstrAgent = NULL, DWORD dwContext = 1, DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG, LPCTSTR pstrProxyName = NULL, LPCTSTR pstrProxyBypass = NULL, DWORD dwFlags = 0);<br />
void OnStatusCallback( DWORD dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength );<br />
};<br />
<br />
void CTempCheckingProgDlg::OnOK() <br />
{<br />
CMyInternetSession* pInetSession;<br />
<br />
pInetSession = new CMyInternetSession("Test1", 1, INTERNET_OPEN_TYPE_DIRECT,NULL, NULL)<br />
<br />
pInetSession->EnableStatusCallback(TRUE); <br />
<br />
CFtpConnection* ftpConnection = pInetSession->GetFtpConnection("10.11.12.13"), "XXX", "YYY" , INTERNET_DEFAULT_FTP_PORT); <br />
<br />
BOOL bVal = ftpConnection->PutFile("SomeFile", "SomeFile_X");<br />
<br />
DWORD Err = GetLastError();<br />
}<br />
<br />
void CMyInternetSession::OnStatusCallback( DWORD dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength )<br />
{<br />
AFX_MANAGE_STATE(AfxGetAppModuleState());<br />
<br />
switch( dwInternetStatus )<br />
{<br />
case(INTERNET_STATUS_REQUEST_COMPLETE):<br />
AfxMessageBox("INTERNET_STATUS_REQUEST_COMPLETE");<br />
Break;<br />
<br />
modified on Monday, February 18, 2008 7:52 AM
|
|
|
|
|
OnStatusCallBack() is called if enabled and the operation is pending completion.
since ftpConnection->PutFile() returns successfully, i think it is not pending for completion, so no status callback.
This is only my guess, try sending larger file.
|
|
|
|
|
Thanks .... But
But i did Enable the callback - and the function OnStatusCallBack() is call - but I'm not sure that this call is really Callback call ( i except that this call will be from other thread and i see that this call is from the same thread.
Can someone help here.... ?
|
|
|
|
|
Yanshof wrote: pInetSession = new CMyInternetSession("Test1", 1, INTERNET_OPEN_TYPE_DIRECT,NULL, NULL)
Why have you not specified INTERNET_FLAG_ASYNC ? There is also a missing semicolon.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The flag INTERNET_FLAG_ASYNC is not relevant -
When i add this flag i getting ASSERT ( on the constructor ( first line of the constructor ) ) of the function "CInternetSession" (in my case the function "CMyInternetSession").
So i remove this flag - and from what i see - this flag is not relevant ( Maybe i wrong ... )
|
|
|
|
|
Yanshof wrote: When i add this flag i getting ASSERT...
I see that now. Have you considered that to handle any operations asynchronously, you must either create your own thread or use the WinInet functions without MFC.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I try to use WinInet also ( i try to avoid of using thread ) here is the code
[ The problem is that the CALLBACK function does not call at all ]
<br />
<br />
HINTERNET hInternetSession;
HINTERNET hFTPSession;
HINTERNET hFileConnection;
<br />
INTERNET_STATUS_CALLBACK iscCallback;<br />
<br />
hInternetSession = InternetOpen("Test1", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);<br />
<br />
iscCallback = InternetSetStatusCallback(hInternetSession, (INTERNET_STATUS_CALLBACK)_OnStatusCallBack);<br />
<br />
hFTPSession = ::InternetConnect(hInternetSession,
"10.11.10.11",
INTERNET_INVALID_PORT_NUMBER,
"XXX",
"YYY",
INTERNET_SERVICE_FTP,
INTERNET_SERVICE_FTP,
0);
<br />
<br />
<br />
::FtpGetFile(hFTPSession,<br />
"File",<br />
"File_X",<br />
FALSE,<br />
FILE_ATTRIBUTE_NORMAL,<br />
FTP_TRANSFER_TYPE_BINARY,<br />
0);<br />
<br />
<br />
modified on Monday, February 18, 2008 9:29 AM
|
|
|
|
|
Yanshof wrote: 0); // Synchronous mode
This would appear to conflict with INTERNET_FLAG_ASYNC .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
No,
This param is Specifies the application-defined value that is used to identify the application context for the returned handle in callbacks.
If/When i add the flag INTERNET_FLAG_ASYNC - nothing happand
|
|
|
|
|
How can I check the exsistence of a Registry Key using C++?
I want the program to perform a certain action if the key does not exist.
Thanks
|
|
|
|
|
RegOpenKeyEx() API returns ERROR_SUCCESS if reg key exist
|
|
|
|
|
Thanks, that was a prompt reply!
How can I assign a certain value to a variable of my choice if the key does not exist?
|
|
|
|
|
J_E_D_I wrote: How can I assign a certain value to a variable of my choice if the key does not exist?
MyChoiceVariableType MyChoiceVariable = MyChoiceInitialValue; :)
if (ERROR_SUCCESS != RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
0, KEY_QUERY_VALUE, &hKey ))
{
MyChoiceVariable = MY_CHOICE_VARIABLE_VALUE; :)
}
modified on Monday, February 18, 2008 9:11 AM
|
|
|
|
|
I get error C2065: 'hKey' : undeclared identifier. Have I missed something? Here is my code:
int MyChoiceVariable = 1;
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ProgramX\\Key", 0, KEY_QUERY_VALUE, &hKey ))
{ MyChoiceVariable = 0;
cout << MyChoiceVariable << endl;
}
|
|
|
|
|
J_E_D_I wrote: error C2065: 'hKey' : undeclared identifier
so u r now in this stage, to write a registry based program.
I was already wondering in ur previous post asking how to assign a variable.
Any way let me complete the code.
declare hKey,
HKEY hKey = NULL;
modified on Monday, February 18, 2008 2:06 PM
|
|
|
|
|
That's great, now it works! I am reporting below a simplified code for who's joined the post only now.
//If you want to check if a Registry key exists:
HKEY hKey = NULL;
string MyChoiceVariable;
if (ERROR_SUCCESS != RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\..", 0, KEY_QUERY_VALUE, &hKey ))
{ MyChoiceVariable = "KEY DOES NOT EXIST";
cout << MyChoiceVariable << endl;
}
if (ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\..", 0, KEY_QUERY_VALUE, &hKey ))
{ MyChoiceVariable = "KEY EXISTS";
cout << MyChoiceVariable << endl;
}
Now the next (and final!) question is...what if I want instead to check if a REG_DWORD value exists?
|
|
|
|
|
J_E_D_I wrote: ...I want instead to check if a REG_DWORD value exists?
Have you considered RegQueryValue() ?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
That's great, now it works! I am reporting below a simplified code for who's joined the post only now.
//If you want to check if a Registry key exists:
HKEY hKey = NULL;
string MyChoiceVariable;
if (ERROR_SUCCESS != RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\..", 0, KEY_QUERY_VALUE, &hKey ))
{ MyChoiceVariable = "KEY DOES NOT EXIST";
cout << MyChoiceVariable << endl;
}
if (ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\..", 0, KEY_QUERY_VALUE, &hKey ))
{ MyChoiceVariable = "KEY EXISTS";
cout << MyChoiceVariable << endl;
}
Now the next (and final!) question is...what if I want instead to check if a REG_DWORD value exists?
|
|
|
|
|
i just want to confirn whether u are waiting for how to assign your choice variable when using RegQueryValueEx() API for checking REG_DWORD value
|
|
|
|
|
Hi Rajkumar, many thanks indeed for your help. What a relief, after a few attempts I came to a solution (see below). If it wasn't for the help of you guys from the Code Project forum, I would probably be stuck on these painful registry functions for months.. The "help" on MSDN and VS2005 might be ok as a reference only, but is totally useless unless you are an advanced programmer!
///// This code checks if a Value belonging to the opened Registry Key exists or not
unsigned long type=REG_SZ, size=1024;
char res[1024]="";
string MyChoiceVariable2;
HKEY key;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\..", NULL, KEY_READ, &key)==ERROR_SUCCESS)
{
if (ERROR_SUCCESS != RegQueryValueEx(key, "ValueName", NULL, &type, (LPBYTE)&res[0],&size))
{ MyChoiceVariable2 = "VALUE DOES NOT EXIST";
cout << MyChoiceVariable2 << endl;
}
if (ERROR_SUCCESS == RegQueryValueEx(key, "ValueName", NULL, &type, (LPBYTE)&res[0],&size))
{ MyChoiceVariable2 = "VALUE EXISTS";
cout << MyChoiceVariable2 << endl;
}
RegCloseKey(key);
}
|
|
|
|
|