|
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);
}
|
|
|
|
|
J_E_D_I wrote: 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;
}
have you heard about if...else.. clause in C++.
J_E_D_I wrote: RegCloseKey(key);
I appreciate your attempt to use the undiscussed RegCloseKey() API which is necessary.
|
|
|
|
|
J_E_D_I wrote: I get error C2065: 'hKey' : undeclared identifier. Have I missed something?
Yes. You've failed to declare a variable.
"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
|
|
|
|
|
|
Hi guys,
I want to make an array that consists of system defined colors. I wrote the code
System::Drawing::Color Color1[]={Color::Black, Color::Brown, Color::Red};
what delivered the error
'System::Drawing::Color' : a native array cannot contain this managed type
Then I tried this version
Color Color1[] = __gc new Color[];
and I got this error
error C2440: 'initializing' : cannot convert from 'System::Drawing::Color ^' to 'System::Drawing::Color'
Has anyone an idea how to make this work?
Thanks and best wishes
|
|
|
|
|
Going from the 'System::Drawing::Color ^' I would guess that you'd get more help in the Managed C++ / CLI forum than here.
Certainly my help would be rubbish - I'm a MFC/Win32 fossil.
Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
|
|
|
|
|
Click here[^]
May be it will help u .
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Your choice for aks this question on this forum was wrong you must ask Managed C++/CLI[^].
|
|
|
|
|
Hi Experts,
I am creating a Shell Context menu application. When I right click on any folder or file, I display the path of file/folder.
I used the following code to get the path of selected files/folders:
<br />
<br />
void CCoMenHandler::GetSelectedFiles(LPCITEMIDLIST pidlFolder,IDataObject *pdtobj)<br />
{<br />
g_szSelectedFiles.RemoveAll();<br />
<br />
if (pdtobj) <br />
{<br />
pdtobj->AddRef();<br />
<br />
STGMEDIUM medium;<br />
FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};<br />
<br />
HRESULT hr = pdtobj->GetData (&fe, &medium);<br />
if (FAILED (hr))<br />
{<br />
GetRecycleBinFiles();
return ;<br />
}<br />
<br />
char path[MAX_PATH];<br />
<br />
UINT fileCount = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF,<br />
path, MAX_PATH);<br />
<br />
if (fileCount>0)<br />
{<br />
g_szSelectedFiles.SetSize(fileCount);<br />
<br />
for (UINT i=0;i<fileCount;i++) <br />
{<br />
memset(path, 0, MAX_PATH);<br />
if (DragQueryFile((HDROP)medium.lpszFileName, i, path, MAX_PATH)) <br />
{<br />
g_szSelectedFiles.SetAt(i, path);<br />
}<br />
}<br />
<br />
g_szSelectedFiles.FreeExtra();<br />
}<br />
<br />
ReleaseStgMedium(&medium);<br />
}<br />
}<br />
<br />
But If I click on file shortcut(.lnk) file it displat the target path of file, although .lnk itself also a file.
I want to retrive shortcut (.lnk) file path.
|
|
|
|
|
Hello all,
I am developing application to open http connection.
I have used CInternetSession, CHttpConnection, CHttpFile to make Application.
My Code is as Bellow:
<br />
CInternetSession iSession;<br />
CHttpConnection *httpCon = iSession.GetHttpConnection(L"localhost", 80, L"", L"");<br />
CHttpFile *httpFile = httpCon->OpenRequest(L"POST", L"test/test.php"); <br />
BOOL x = httpFile->SendRequest();<br />
<br />
This code works fine for me.
Now the Problem is that i want to pass parameters using POST method to my request.
So is there anybody who can solve my problem.
Any help will be highly appreciated
Thanks.
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
|