|
I have this app where i need to retrieve some settings from the registry, here's my code:
DWORD dwDisposition;
LPCTSTR SubKey = "SOFTWARE\\MP3Reader";
DWORD KeyLen = 0;
HKEY OpenKey;
DWORD DataType = REG_SZ;
DWORD DataLen;
char Data[MAX_PATH+1];
RegCreateKeyEx(HKEY_CURRENT_USER, SubKey, 0, NULL, 0, KEY_READ, NULL, &OpenKey, &dwDisposition);
if (dwDisposition == REG_OPENED_EXISTING_KEY)
{
RegEnumValue (OpenKey, 0, KeyValue, &KeyLen, NULL, &DataType, (unsigned char *)Data, &DataLen);
SetDlgItemText (hWnd, IDC_FILEPATH, (LPCTSTR)Data);
}
RegCloseKey (OpenKey);
<pre>
When it comes to the RegCloseKey sentence the following error appears:
Link: http:
I don't understand it cause the Registry handle (OpenKey) is used in RegEnumValue and there it works fine cuase it retrieves the value and fills up the Data variable with the correct data, but when it reaches to that specific sentence it doesen't work even though the variable hasn't been manipulated.
Thanks for the help!
|
|
|
|
|
You first must to open the RegKey with RegOpenKeyEx . The last parameter will return you the Handle of the opened key, that you must to use in RegCloseKey
Bets Regards
Carlos Antollini.
www.wanakostudios.com
Sonork ID 100.10529 cantollini
|
|
|
|
|
The RegCreateKeyEx function will, if the registry key already exist, open the existing key and return it in the 8th parameter:
LONG RegCreateKeyEx(
HKEY hKey,
LPCTSTR lpSubKey,
DWORD Reserved,
LPTSTR lpClass,
DWORD dwOptions,
REGSAM samDesired,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
PHKEY phkResult,
LPDWORD lpdwDisposition
);
And i also tried it before where it worked, i don't know why it doesen't work now...
|
|
|
|
|
Try checing the error codes on all the calls. Make sure they are returning 0s.
Good Luck,
Bill
|
|
|
|
|
Check if RegCreateKeyEx returns ERROR_SUCCESS and close the key only if it is successful.
if (RegCreateKeyEx(...) == ERROR_SUCCESS)
{
// your code here
RegCloseKey(...);
}
Like it or not, I'm right.
|
|
|
|
|
is there some mysterious unwritten law against inheriting INDIRECTLY from MFC classes?
i'm having all sorts of trouble trying to do something very simple. here is an example of my woe:
I'd like to create my own Wizard property sheet class, derived from CPropertySheet. ok, well- that's all fine and good, as long as I use the class that inherits directly from CPropertySheet. but try to add another layer, and forget it. will NOT compile.
same thing now happening with CPropertyPage. I'm trying to make a bunch of pages for my wizard, and they share common characteristics. seems like the textbook case of where to use a base class. I'd like to make my base class, WizardPage (or whatever) inherit from CPropertyPage. then all of my actual pages inherit from WizardPage.
no matter what i try, this will not compile. if i try to use one of the child classes, it says "base class undefined" or something. trust me, i included the right headers.
i would be forever grateful to anyone who can explain why this is happening.
~L
|
|
|
|
|
There is nothing wrong with what you are trying to do. There is no limitation of inheritance from MFC classes or CPropertySheet.
Sorry, but the problem is in your code.
here is a sample:
[ccode]
// Derived.cpp: implementation of the CDerived class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RegHelper.h"
#include "Derived.h"
#include "MyPropSheet.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDerived::~CDerived()
{
}
CDerived::CDerived(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CMyPropSheet(nIDCaption, pParentWnd, iSelectPage)
{
}
/////////////////////////////////////////////////////////////////////////////
// CMyPropSheet
class CMyPropSheet : public CPropertySheet
{
DECLARE_DYNAMIC(CMyPropSheet)
// Construction
public:
CMyPropSheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
CMyPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyPropSheet)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyPropSheet();
// Generated message map functions
protected:
//{{AFX_MSG(CMyPropSheet)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
[/ccode]
Hope this helps,
Bill
|
|
|
|
|
thanx for the response. i did in fact find the problem not too long after i posted the question.
the main thing i've found is that you have to be really careful about the Class Wizard. it's helpful, but only up to a point. (like, up to the point where you add another level of inheritance to your class heirarchy- eg, if i were to make a class inherit from your CMyPropSheet)
anywyas, thanx again for taking hte time to help out.
~L (spoongirl)
|
|
|
|
|
how to set radio button to be checked?
i want to checked radio button when user go to a menu bar, action menu, and choose menu item named check.
|
|
|
|
|
Check out:
BOOL CheckDlgButton(
HWND hDlg, // handle to dialog box
int nIDButton, // button identifier
UINT uCheck // check state
);
or
void CWnd::CheckDlgButton( int nIDButton, UINT nCheck );
--------
CheckDlgButton(IDC_MY_RADIO_BTN, BST_CHECKED);
HTH,
-Wes
Sonork ID 100.14017 wtheronjones
|
|
|
|
|
If you are using a CButton, use SetCheck(1) to check or SetCheck(0) to uncheck.
Like it or not, I'm right.
|
|
|
|
|
You can use the BM_SETCHECK message:
SendMessage(
(HWND) hWnd,
BM_SETCHECK,
(WPARAM) wParam;
(LPARAM) lParam;
);
|
|
|
|
|
|
I have created a dll in which I use the following linkage interface:
#ifdef CONSOLEDLL_EXPORTS
#define CONSOLEDLL_API __declspec(dllexport)
#else
#define CONSOLEDLL_API __declspec(dllimport)
#endif
every classes have been declared like this:
class CONSOLEDLL_API CCenteredStepEdger : public CStepObject{
friend CONSOLEDLL_API ostream& operator <<( ... );
friend CONSOLEDLL_API istream& operator >>( ... );
...
and some of the classes use fstream type variables:
fstream m_File;
when I compile the project, I have the following warning:
class 'fstream' needs to have dll-interface to be used by clients of class 'CCenteredStepEdger '
How should I specify the dll-interface for the fstream variables???
Thanks
Daniel Verret
|
|
|
|
|
I'd like to know how I can find out if two drive letters refer to partitions on the same hard drive.
I'm working on a database backup utility, & I want to discourage users from selecting the same physical hard drive for their backups as the hard drive where their 'live database' is running.
ie: If "C:\LiveDatabases" and "D:\My Backups" are actually located on the same physical harddrive(on different partitions), I'd like to know how to determine this info.
Thanks!
Wes
Sonork ID 100.14017 wtheronjones
|
|
|
|
|
Try checking out this site: http://www.users.intercom.com/~ranish/part/primer.htm
|
|
|
|
|
Thanks for the informative link, but I'm looking for API's that I'd be able to use to figure this out.
Thanks!
-Wes
Sonork ID 100.14017 wtheronjones
|
|
|
|
|
Not sure if this will give you the right info, but check out the GetVolumeInformation function on MSDN and the lpVolumeSerialNumber parameter.
Like it or not, I'm right.
|
|
|
|
|
I thought might be it, but I hadn't tested it yet...
thanks!
Wes
Sonork ID 100.14017 wtheronjones
|
|
|
|
|
Can an ISAPI Filter be used to catch content being sent to an FTP site?
Thanks,
ed
'Love is an obsessive delusion that is cured by marriage.' Dr. Karl Bowman
|
|
|
|
|
No. I believe ISAPI only filters HTTP requests.
Hope this helps,
Bill
|
|
|
|
|
Thanks...that is what I thought.
ed
'Love is an obsessive delusion that is cured by marriage.' Dr. Karl Bowman
|
|
|
|
|
How can I get IP address of any computers that connect to my computer through a CSocket variable ?
Ex: My computer run a program as a server, using a CSocket variable, listen to connection.
Client run a program connect to server at port 0 by a CSocket variable.
I want to get IP address of the client !
How to ?
Hung Son
A Vietnamese student
i-g.hypermart.net
dlhson2001@yahoo.com
|
|
|
|
|
Use <a href="http://msdn.microsoft.com/library/en-us/winsock/wsapiref_8woi.asp">getpeername</a> .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I want my app to open a TCP communication thread to work with a certain device, which is not "dumb" in a way it can receive commands and even transmit some data back to my app in its own time. So I created a static thread function inside my control class for this reason only.
But, when I was trying to work with CSocket/CAsyncSocket *inside* the thread's context - MFC started to throw unhandeled execptions at me. so just to check things up - I moved the socket handling code into the main thread/process, and it worked fine there.
again - ALL the socket handling (including object declaration, creation, connect, ect) was done within the thread.
so what's the problem? anyone?
thanks for your help.
|
|
|
|