|
A comment: ALWAYS check the return value from a function that returns one.
Ex:
HKEY hKey = NULL;
CHAR szBuf[100];
LPDWORD lpdwLength;
CString strReturn;
LONG lResult = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, "CLSID", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &hKey, NULL);
lResult = ::RegQueryValueEx(hKey, "E1", 0, 0, (LPBYTE)szBuf, lpdwLength);
::RegCloseKey(hKey);
by knowing the return value, you will know what is going wrong.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
lpdwLength should be the address of a dword, not an uninitialised pointer pointing into randomness.
The value in that dword is size of the buffer you're passing in, or 0 if you're not passing a buffer. After the call it's the size of the buffer required (or the size of the buffer that was used (same thing)). It kinda says all that in the MSDN docs.
So, something like this might work (beware, it hasn't seen a compiler). Or you can try a wrapper class, like the one I wrote about here.
HKEY hKey = NULL
long ret = ::RegCreateKeyEx(
HKEY_CLASSES_ROOT,
"CLSID",
0,
NULL,
REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,
NULL,
&hKey,
NULL);
if (ret == ERROR_SUCCESS)
{
CHAR szBuf[100];
DWORD dwLength = sizeof(szBuf);
ret = ::RegQueryValueEx(hKey, "E1", 0, 0, (LPBYTE)szBuf, &dwLength);
if (ret == ERROR_SUCCESS)
{
}
::RegCloseKey(hKey);
}
else
{
}
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Len,
Thanks for the advice. I am still learning how to decipher the cryptic documentation that is MSDN...
Anyways, I tried this and now get "access violation reading location ..." during the query. The access specifier is set to
KEY_READ | KEY_WRITE | KEY_QUERY_VALUE
Any suggestions???
|
|
|
|
|
Try using KEY_ALL_ACCESS?
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
I have two dialog based programs. one is Microsoft Automation. and the other one calls first dialog-based app.
To call first dialog-based app ( let me just say it app2) from first dialog-based app ( app1), I used ShellExecute();
anyway, It is working fine if you compile and execute app1.exe within VC++ 6.0.
if you go to mycomputer-> right click-> window explore->go to app1 folder->debug-> app1.exe, and it is not working anymore.
the error at, which is in app2
<br />
_Application application;<br />
if(!application.CreateDispatch("Word.Application)<br />
{<br />
AfxMessageBox("Couldn't create Word.Applicaiton");<br />
<br />
}<br />
if I go back to run and execute app1.exe it works again. but not from double clicking on app1.exe in window explore.
I know that's OLE initialization problem where i declare
<br />
if(!AfxOleInit())<br />
{<br />
AfxMessageBox("Couldn't create OLE COM");<br />
}<br />
<br /> it is in BOOL Capp2App::InitInstance(). From my knownladge, if OLE libs didn't get initialized, I couldn't createDispagech("Word.Application");
How can I initialize OLE Lib evertime i use so i don't have to execute app1.exe inorder to get Word.Application?
|
|
|
|
|
Hi!
How can I put an clickable email and weblink on a dialog (like the about dialog)?
The email-link should open the standard email program on the system and the weblink should open the standard browser.
Thanks for any help!
Dirk
|
|
|
|
|
|
Thank you!
|
|
|
|
|
I have head file and cpp file are written in C++. There is a GetItem() in it. I used it in a C file to create a lib file. The compile is fine. Then I use this lib file in a C++ application and got a Link2001 link error which says "unresolved external symbol _GetItem".
Anyone knows how to fix this problem? Thanks.
mIchAel Liu
__________________________________________________________
The secret of business is to know something that nobody else knows.
|
|
|
|
|
You need to reference the library where the _GetItem function is implemented.
|
|
|
|
|
you should link the .lib
if in vc, should be at "project setting"->link->object/library type in the libary name will be ok
i am realfly8)
|
|
|
|
|
Also, if the GetItem implementation is in a C file do not forget the extern "C" stuff:
extern "C"
{
#include "Header_in_C_That_Contains_GetItem.h"
}
Best regards,
Alexandru Savescu
|
|
|
|
|
Hello,
I've searched the MSDN to no avail...
I've created a CSlider control on a DialogBar and am constantly getting an assertion error (hWnd is not valid) when I try to set the range (CSliderCtrl::SetRange(0, 50, FALSE)). It's as though I'm trying to set it before the slider control window is 'valid' (or created?), however, the error occurs after I see the slider physically on my DialogBar, so I know it exists at the time I try to SetRange().
If I 'ignore' the first assertion error, all subsequent executions work fine.
At what time in the code execution (standard wizard or MFC methods) may I set the slider control's parameters without error? Or does anyone know what is going wrong with this scenario? I really want to learn. Thanks!
JennyP
|
|
|
|
|
The easiest thing to do would be to put a check on the slider's hWnd member:
if( m_SliderCtrl.m_hWnd == NULL )
{
m_SliderCtrl.SetRange(...);
}
That'll stop it asserting.
You need to make sure that the OnInitDialog member has been called first (by the framework, that is, don't call it yourself.)
I've also found that doing an UpdateData( FALSE ); call before you first access the control makes sure that the control variable is actually initialised properly
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Thanks for the reply. I ended up calling UpdateData(FALSE) in the CMainFrame just after this dialog bar is created (and initializing other aspects such as ticks, range, etc.). It doesn't feel very like good OOD, but it's the one sure place that I can consistently initialize my DialogBar controls.
Also, I assume in the code fragment you wrote, you meant to write a != NULL instead of a == NULL?
Thanks!
JennyP
|
|
|
|
|
JennyP wrote:
Also, I assume in the code fragment you wrote, you meant to write a != NULL instead of a == NULL?
Yeah, sorry
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I would like to see all the ICMP messages coming to my machine. I wrote the following code but I can not read anything from the socket. Where is my mistake ?
SOCKET hSocket = ::socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
while (true)
{
sockaddr_in from;
int nFromlen = sizeof(from);
int nRead = recvfrom(hSocket,pRecvBuf,1024,0,(sockaddr*)&from,&nFromlen);
}
When I ping another machine from dos prompt I expect to catch something but nothing happens and recvfrom blocks. I have admin privileges. Can someone help me on this subject please. I could not solve it.
Thank you
Orcun Colak
|
|
|
|
|
Dear All,
is there any way to develop plugin for IExplorer. if yes then plz
if some one of you can reffer me to the materail for this help.
any code examples or any tutorial on the net.
waiting for reply.
omar lodhi
|
|
|
|
|
is there a way i could disable the menus from my code
the code in msdn(july 2002) gives me a runtime exception.
thanks
looking forward from all the gurus of code
|
|
|
|
|
*ahem*
we are projects of code here... or something like that.
Anyway, could you give a few more details? Are you using MFC, or straight Win32? Do you need to disable one menu, or all of them, or just certain ones? And what have you tried (i don't have the july MSDN here)?
For reference, the functions EnableMenuItem() and potentially DrawMenuBar() will most likely be your starting point.
Shog9
--
Maybe Java is kind of like God, it "works in mysterious ways". It seems like your apps are running slowly, because in the backgroud Java is solving world hunger, or finding the cure to cancer.
- Ryan Johnston, Don't die java!
|
|
|
|
|
i have tried using
pMenu->AppendMenu(MF_STRING | MF_DISABLED, 0, "Insert");
and
the submenu pointer code
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(4);
if (menuID == IDM_VIEW_OBJECTONLY) {
submenu->CheckMenuItem(IDM_VIEW_OBJECTONLY, MF_CHECKED | MF_BYCOMMAND);
submenu->CheckMenuItem(IDM_VIEW_PATHOBJECT,
and some thing from msdn .. which was more simpler
but all things give me one same run time error..
looking forward from all the gurus of code
|
|
|
|
|
SilentWarrior wrote:
but all things give me one same run time error
What run time error is that?
The code looks right (though cut off); if i were to guess, i'd say maybe 4 is the wrong indice for the menu you're looking for. Step through with a debugger & see what the return values are for each stage.
Shog9
--
Maybe Java is kind of like God, it "works in mysterious ways". It seems like your apps are running slowly, because in the backgroud Java is solving world hunger, or finding the cure to cancer.
- Ryan Johnston, Don't die java!
|
|
|
|
|
hi,
I'm trying to gain access to a 16-bit app.
i'm trying something like :
::readProcessMemory(ProcHandle, (LPVOID)OffSet, buffer, BytesToRead, &BytesRead);
this doesn't work.
I did some research and it seems that all 16-bit apps operate in the same address space.
Well, ... I found a DLL (toolhelp.dll) with which I can get the Job done but only in WIN9x.
I need something to get the job done under NT too.
preferably I'm looking for a way that works equally good in all environments.
thx & greetz
I used to have a life ... now I have a computer
|
|
|
|
|
Help,
I'm trying to launch a new IE instance from a CHtmlView based SDI application.
The code is as follows:
CWinApp* pApp = AfxGetApp();
CDocTemplate* pDocTemplate;
POSITION pos = pApp->GetFirstDocTemplatePosition();
pDocTemplate = pApp->GetNextDocTemplate(pos);
CDocument* pDoc = pDocTemplate->CreateNewDocument();
CFrameWnd* pNewFrame = pDocTemplate->CreateNewFrame(pDoc/ *GetDocument()* /,
NULL/ *(CFrameWnd*)AfxGetMainWnd()* /);
pDocTemplate->InitialUpdateFrame(pNewFrame, NULL);
CPeachPlorerView* pView = (CPeachPlorerView*)pNewFrame->GetActiveView();
pView->SetRegisterAsBrowser(TRUE);
*ppDisp = pView->GetApplication();
Unfortunately the new frame is parented to the previous one. I think the CDocTemplate framework inherit the same CWinApp. So when I close the parent the child is closed to.
The best way would be to launch a new instance of my application, and keep a handle on it so that I can pass the IDispatch interface (ppDisp). I mean initializing the SDI from another. I've no idea on how to do this. Can somebody help me ?
Yarp
|
|
|
|
|
What is the Win32 API equivalent of MFC's ModifyStyle ?
rechi
|
|
|
|
|