|
Hi All,
Can anyone please explain me on how to write a variable(integer type) into the registry and also how to read it back
Thanks
Uday
|
|
|
|
|
Check the API function with names starting with Reg prefix, like RegSetValueEx. If you're using MFC, you can also use CWinApp::WriteProfileXXX methods.
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
Following code isn't perfect but it works and should get you started. If you look at the documentation for RegSetValueEx() you can set the dwType param to REG_DWORD for numbers but I usually just deal with strings and use atoi() or similar to convert.
bool bGetRegistryEntry(const HKEY hKey, const char* name, unsigned char* const dest)
{
bool bReturnVal = true;
unsigned long lType = 0;
unsigned long ulSize = MAX_PATH;
if (ERROR_SUCCESS != RegQueryValueEx(hKey, name, NULL, &lType, dest, &ulSize))
{
bReturnVal = false;
}
return (bReturnVal);
}
bool bSetRegistryEntry(const HKEY hKey, const char* name, unsigned char const* dest)
{
bool bReturnVal = true;
unsigned long lType = 0;
LONG lRESULT = 0;
lRESULT = RegSetValueEx(hKey, name, 0, REG_SZ, dest, _mbslen(dest) + 1);
//ERROR_ACCESS_DENIED indicates it already exists
if ((lRESULT != ERROR_SUCCESS) && (lRESULT != ERROR_ACCESS_DENIED))
{
bReturnVal = false;
}
return (bReturnVal);
}
// Open or create registry.
void vRegOpenKey()
{
HKEY hKey=0;
//char *my_App = "Registry_Example";
CString sAppId = "SOFTWARE\\RegKeyExample";
bool bReturnVal = false;
DWORD dwDisposition = 0;
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, sAppId, 0, KEY_READ, &hKey))
{
LONG lRESULT = 0;
lRESULT = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
sAppId,
0,
REG_NONE,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition);
if (lRESULT != ERROR_SUCCESS)
{
MessageBox(NULL, "Registry not available!", NULL, NULL);
return;
}
}
const unsigned char name[5] = "this";
if (!bSetRegistryEntry(hKey, "value1", &name[0]))
{
MessageBox(NULL, "Unable to set registry value1", NULL, NULL);
}
else
{
unsigned char name2[5];
if (bGetRegistryEntry(hKey, "value1", name2))
{
CString sText;
sText.Format("Registry value1 is %s", name2);
MessageBox(NULL, sText, NULL, NULL);
}
else
{
MessageBox(NULL, "Unable to get registry value1", NULL, NULL);
}
}
RegCloseKey( hKey );
}
|
|
|
|
|
Excuse the lengthy post : but I've been getting quite frustrated researching this topic, and I'd like to get someones informed advice if possible.
I have written an MFC app, using OpenGL to provide my own custom 3D model editor. I am using the CDocument/View architecture and everything is fine.
Now I want to code plugins for tools that manipulate the data in the model.
Having spent a few days researching on the web, I come to the following conclusions :
1) DLL's should be fairly straightforward to use
2) No two sources agree on how they should be done
3) Microsoft don't help matters.
:S
This is what I want to do :-
a) Create a "tool" class that plugs into the main app (ie. CPluginExtrude).
b) The main app then checks its plugins directory on loading, for any .dll's present, installs them, and attaches them to the CMainFrame menu so that the user can invoke them.
c) The plugin is given a pointer (on initialisation) to the CDocument derived model, and the main app so that it has full access to the application and its data.
d) When a plugin is invoked, it may simply perform it's function on the model data, or it may invoke a dialog asking for parameters beforehand.
e) It is vital that I can create plugins as and when, without the necessity to recompile/rebuild the main application.
I have coded a partial plugin implementation - which works upto the pointer where I attempt to use GetProcAddress to find a function pointer by its name, this always returns null, even though the function I am trying to obtain has been declared with __declspec (dllexport) in the plugin .dll
I am using VC6, and the W2K MFC dll's
Having rattled off all of that, if someone can supply a link to a site that explains all (which I have as yet been unable to find ) then that would be great...
Thanks in advance!
(PS : I may provide the results of my research & solution as an article somewhere - possibly gamedev - and full credit will be given )
|
|
|
|
|
makom42 wrote:
which works upto the pointer where I attempt to use GetProcAddress to find a function pointer by its name, this always returns null, even though the function I am trying to obtain has been declared with __declspec (dllexport) in the plugin .dll
The trick is to use both extern "C" and __cdecl - this way your function name won't be mangled by the compiler and you'll easily get the pointer:
extern "C" __declspec(dllexport)
void __cdecl ZoopaDoopa(CRuntimeClass *&pViewClass, CRuntimeClass *&pFrameClass)
{
...
}
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
Already being done...
I am convinced this is something stupid somewhere... a missing macro definition or something... thanks anyway Tomasz
|
|
|
|
|
1) Check plugin dll with depends.exe. Right click on .dll icon in the Windows Explored and select 'View dependencies'. You'll see the list of functions exported from your .dll. Ensure that function names aren't mangled - they shouldn't contain @ characters and letters/digits appended by compiler
2) If you're absolutely sure that plugin exports the functions, check the GetProcAddress side. Ensure that function name isn't misspelled. Check the HMODULE you're passing to GetProcAddress. If it still fails, call GetLastError() and post result here.
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
I wrote an article on some of things your talking about here.
docviewfromdll[^]
The example APP/DLL projects in it show a nice way of loading in plug-in DLL's. You should be ble to extend the interface example to do the kind of things that your talking about.
I am in the process of planning a series of articles on this subject, but just havn't had the time to work on them yet.
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Hi,
I'ld like to have different views in the same canvas.
Something like the VC++ file where we have separate views for workspace and output. But each of them has it own scroll bar, etc.
Can someone help me out with this, or direct me to the link which explains about it...
Thanx in advance...
|
|
|
|
|
|
Using Spy++ I can see when a control is posted a WM_PAINT message. Is there anyway to tell when a control has finished its painting?
Thanks
|
|
|
|
|
The reason that you cannot tell that the WM_PAINT message has ended in Spy++ is because it is ALWAYS posted.
Is there something that you are trying to accomplish and maybe we can help you that way?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
In the form designer for Visual Studio you can put a number of buttons on top of each other. In fact you can completely cover one with another. But when you select all the buttons on the form every button’s selection rectangle is displayed - even the one that is completely covered. (You can see bottom button’s selection rectangle drawn OVER the top most button even though the bottom button is completely hidden below the top most button.)
I need to know when all the controls (buttons) on a form are done painting so I can then paint my selection rectangles to the screen (and over any covering control).
Here’s the kicker: I’m doing this in C# and there does not seem to be anyway to do this in a straightforward way. (I have a couple other ideas/suggestions that involve overriding each control’s Paint event or using a window atop the main form.) But I’m hoping that there is someway to do this from a low-level windows perspective. Thus my foray into windows messages and my post here in this forum.
I’ve seen the message WM_QUERYUISTATE pop up in Spy++ for a number of windows but there isn’t much documentation for this message. I’m wonder if I can use it or some other message to determine when the form is finished painted so I can go ahead and paint the selection rectangles over the top of the entire form.
|
|
|
|
|
Actually I want to capture the screen whenever it is updated. I know how to capture the screen and store it as bitmap file but I don't know when to capture...I mean how can my program can know about the screen change. Please help me......
C.R.Naik
|
|
|
|
|
If any program on your desktop recieves WM_PAINT then the screen has changed. If you're hoping to capture video, you're better off to go for 15 fps, I mean, if it only captures on change, the end result will be rather jerky....
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
you get a strange error message when you post as 'Anonymous'. Instead, a message telling you need to choose a nick would be better?
|
|
|
|
|
This problem has been fixed.
cheers,
Chris Maunder
|
|
|
|
|
I have a frame window with a menu. when i click one menu item, dialog is created. Now after entering some values into the dialog, i click "OK". here i have a problem. That is, I want to get a field value of the dialog into my frame window. This is the code for the command handler.
void MyCFrameWnd::OnDialog1(){
userDialog1 dlg1;
dlg1.DoModal();
// In this handler i want to get a value from
// the dialog
}
Please help me asap
Thanking you
|
|
|
|
|
Use the DDX features to capture data for your dialog.
Basically this will allow you to assign the edit fields and other controls of your dialog to a member variable that you create in the userDialog1 class.
Then after you call DoModal, you will be able to access the member variables of that class and grab the data that you need.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
In your userDialog1 you make control variables for each control to be visible. That is eg. for a Edit-field you have a variable of type CEdit.
Class Wizard can help you with this.
Then, after DoModal() returned with IDOK, you can access the contents of the Edit-field.
Hope this helps
P.S. DDX is evil...
|
|
|
|
|
hi,
I'ld like to create a CListCtrl object using Create(...) in my CView class.
The function declaration for Create is:
BOOL CListCtrl::Create(DWORD dwStyle,const RECT& rect,CWnd* pParentWnd,UINT nID)
Can someone tell me what's meant by nID (fourth argument) and how to set that value??
Thanx in advance...
|
|
|
|
|
just what it sounds like - it's a number you can use to identify the control by, for instance when using GetDlgItem() or identifying it as the source of notification messages. It can be whatever number you feel like using, although if you plan on actually making use of it then it should be unique amoung the other controls on your form.
---
Shog9
Actually I use to find learning in bars when drinking really useful.
It sort of makes a language liquid. - Colin Davies, Thinking in English?
|
|
|
|
|
Hi,
thanx for that info...
now, i created a CListCtrl using the following code:
<br />
CListCtrl* m_ctrlMesgList = new CListCtrl();<br />
CRect rect(0,650,800,800);<br />
<br />
m_ctrlMesgList->Create(LVS_ALIGNLEFT | LVS_REPORT, rect, this, 1);<br />
m_ctrlMesgList->InsertColumn(0,"Date",LVCFMT_LEFT,-1,-1);<br />
m_ctrlMesgList->InsertColumn(1,"Time",LVCFMT_LEFT,-1,-1);<br />
The problem is, no listctrl is created. This piece of code is in CView::OnInitialUpdate()
Thanx in advance...
|
|
|
|
|
tulc_kris wrote:
m_ctrlMesgList->Create(LVS_ALIGNLEFT | LVS_REPORT, rect, this, 1);
Did you check the return value? What was it?
Anyway, you'll probably want a few other styles. Definately add WS_CHILD|WS_VISIBLE . You may also want WS_BORDER .
---
Shog9
Actually I use to find learning in bars when drinking really useful.
It sort of makes a language liquid. - Colin Davies, Thinking in English?
|
|
|
|
|
Hi All,
I have 2 separate applications say X1 and X2,
X1 receives all the data and stores it in a file now this file should be opened through X2
Consider for example,
GetLogic() fn. in X1 gets the logic from the device and stores it into a file and immidiately this file should be opened through X2
This should happen at run time
User intervention will come only once when he selects GetLogic()
I beleive that DDE should be made used but anyone can explain me the procedure or if there is any other method??
Thanks
Uday
|
|
|
|
|