|
Hello Friends,
I need to Convert WCHAR string into BYTE * To Use in the RetSetValueEx() function as it takes the value in BYTE Format. But dont know How to Do It.
I am Using Following code.
When I dubug the Programme the Value of the Byte seem to be Ok in the Debugger. But I am using this BYTE value to set it in the registry. And when I see in the Registry I only able to see this 㩃坜义呎 .
The Code I am using is as follow.
<br />
TCHAR *Path;<br />
char ch[256] = {};<br />
BYTE *Byte;<br />
RegOpenKey(HKEY_CURRENT_USER,L"Software\\PersonalMenu",&hKey);<br />
Byte = new BYTE[strlen(ch)];<br />
Byte =(BYTE *) ch;<br />
Byte[strlen(ch)] = NULL;<br />
RegSetValueEx(hKey,Name,0,REG_SZ,Byte,sizeof(Path)*2+1);
|
|
|
|
|
Are you quite sure you need to "convert" it and not just cast it using (LPBYTE). If you are compiling with UNICODE then RegSetValueEx isexpanded to RegSetValueExW by the precompiler and the string should be UNICODE in a WCHAR*. If you are compiling without UNICODE then it is expanded to RegSetValueExA and the string, which should be ANSI in a char*, is converted to UNICODE before being stored.
|
|
|
|
|
That was the First thing I have done. I When I simple Type Cast it and Put dutring settring the registry It doenst take the whole path;
For Example this is the code privously using. And now I got it where is the problem. its in sizeof() function.I was using it wchar.
void AddInReg(WCHAR *Name,TCHAR *Path)<br />
{<br />
HKEY hKey;<br />
RegOpenKey(HKEY_CURRENT_USER,L"Software\\PersonalMenu",&hKey);<br />
RegSetValueEx(hKey,Name,0,REG_SZ,(BYTE *)Path,sizeof(Path));<br />
}
Now I have replaced the sizeof(Path) with wcslen(path)*2+1;
and Its Working.
|
|
|
|
|
Your string handling is, well, all messed up. You have three different variables there, but none hold a meaningful string. You are also passing a non-Unicode string to the Unicode RegSetValueEx() API. This is wrong - REG_SZ means a zero-terminated string that matches the character set that the API is expecting.
|
|
|
|
|
Hi,
I want to add a underlined hyperlink on a dialog box as a text and taking mouse over it makes it blue and on clicking on it an instance of internet explorer opens with the specified URL hyperlink.
i want to do this in an mfc application as it happens in webshots desktops application.
Thanks In advance
Dhiraj
Dhiraj Kumar saini
|
|
|
|
|
|
|
If you will always run on XP or later, use the built-in SysLink control. Otherwise, check out CHyperLink in WTL, or any of the other hyperlink controls in the previous posts.
|
|
|
|
|
My problem is that i want to open an instance of internet explorer on click of a context menu item with a certain URL. I have the event handler function for context menu item. I wan only the code for the above mentioned work to be inserted into it.
Thanks In Advance.
dhiraj
Dhiraj Kumar Saini
|
|
|
|
|
Hi,
ShellExecute(NULL,"open","www.codeproject.com",NULL,NULL,SW_SHOW);
should work
|
|
|
|
|
Thanks alot it worked.
Great man u r excellent!
Dhiraj
|
|
|
|
|
Might b code underneath will help u.
<br />
STARTUPINFO si;<br />
PROCESS_INFORMATION pi;<br />
si.cb = sizeof(si);<br />
ZeroMemory( &si, sizeof(si) );<br />
ZeroMemory( &pi, sizeof(pi) );<br />
TCHAR str[] = _T("IEXPLORE.EXE http:\\www.codeproject.com");<br />
CreateProcess(NULL,str,0,0,FALSE,0,0,0,&si,&pi);<br />
|
|
|
|
|
This would be bad - what if the user's default browser is firefox?
It's one of my pet peeves about programs like Live Messenger (though they're at least MS programs, so a bias is understandable)
Iain.
|
|
|
|
|
I wonder if somebody could remind me the method of defining a struct where you can set the bits of a member directly, without using the bitwise OR or bitshift operators. ie. I have a struct with 2 members
struct foo
{
BYTE Repaint;
BYTE Offset;
};
The offset member requires only 4 bits, and the repaint only 1. Idealy they could be combined so that the Repaint member uses the high order bit of the same BYTE. I remember seeing a way to do this, possibly using a union, but I cannot remember how or where I saw it.
Waldermort
|
|
|
|
|
Add the number of bits after the member names:
struct foo
{
BYTE Repaint:1;
BYTE Offset:4;
};
|
|
|
|
|
Thanks Mike, that's exactly what I was looking for. Can't think why I thought a union had something to do with it, possibly one of MS's wierd structs...
Waldermort
|
|
|
|
|
There is usefulness in using a union as well.
Below is a code snippet from my software:
union __ChannelsOn
{
BYTE Mask;
struct {
BYTE On1 : 1;
BYTE On2 : 1;
BYTE On3 : 1;
BYTE On4 : 1;
BYTE OnTOF : 1;
BYTE Unused : 1;
BYTE MasterOn: 1;
BYTE ScanOn : 1;
} Bits;
} ChannelsOn;
This is mirroring a register in some hardware I talk to. I can set the variable by twiddling individual bits: ChannelsOn.Bits.MasterOn = 1<code>, and also use it as a whole byte... <code>SendStuffToHardware (...., ChannelsOn.Mask, ....);
So, while its not a linked language construct, it's often handy.
Unions can also be usedto ensure the overall variable ends up the correct size.
Iain.
|
|
|
|
|
I am having trouble understanding what it is your trying to accomplish, however I believe you want to manipulate the bits in these bytes indirectly without accessing struct members, although I can't imagine why you would want to do this. Perhaps you have a high performance application and are attempting to shave off a few operations in a critical function.
If speed is your goal, then you should work with the fastest datatype on a 32 bit operating system, sizeof(int). On a modern Intel Core 2 Duo the following function is the fastest, you should define bit masks in your application. The function does not generate any branching op codes, quite fast.
unsigned int bitset(unsigned int bits,unsigned int mask,bool flag)
{
bits = (bits & ~mask) | (-flag & mask);
}
Best Wishes,
-Randor (David Delaune)
|
|
|
|
|
void CDisplayBody::OnNavigateComplete2(LPCTSTR strURL)<br />
{ <br />
CString pszText="<html><head><body>Hi How r u</body></head></html>";<br />
if (GetBusy())
Stop(); <br />
<br />
IDispatch * pDisp = GetHtmlDocument();<br />
if (!pDisp)<br />
return;<br />
<br />
IHTMLDocument2* pDoc;<br />
if (SUCCEEDED(pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc )))<br />
{<br />
CComBSTR bstrURL;<br />
CComVariant varDummy;<br />
pDoc->open(bstrURL, varDummy, varDummy, varDummy, NULL);<br />
<br />
SAFEARRAY *pSA;<br />
SAFEARRAYBOUND saBound = {1, 0};<br />
pSA = SafeArrayCreate(VT_VARIANT, 1, &saBound);<br />
<br />
VARIANT *pVar;<br />
CComBSTR bstrHTML = pszText;
varDummy = bstrHTML;
<br />
SafeArrayAccessData(pSA, (void**)&pVar);
pVar[0] = varDummy;
SafeArrayUnaccessData(pSA);
<br />
pDoc->write(pSA);
pDoc->close();
<br />
SafeArrayDestroy(pSA);
pDoc->Release();
<br />
}<br />
<br />
}<br />
This code is to display html in html view But the statement (IDispatch * pDisp = GetHtmlDocument();)return Null .Why ? plz help
|
|
|
|
|
Where do you use of strURL and do you want to show a html file?
|
|
|
|
|
hi every one
i wrote one mfc project and called StartService Api .
it work in windows xp correctly but in vista this Api returned 0;
please help me.
|
|
|
|
|
Did you use of GetLastError for see error information?
|
|
|
|
|
hi ,
first tell me did u start u r service under system or admin. context. i think if u start under admin context then in vista u need to give Manifest.
|
|
|
|
|
thanks of my dear friends
i fined my problem.it was in registery .
when i deleted some key in Windows registry ,my program worked correctly.
Good Luck
|
|
|
|
|
hi every one
whats the means of \\\\.\\ in path?
current directory or system directory?
please help me.
|
|
|
|