|
I try to read all ODBC installed on , with this[^] sample , as with modify follow target :
#define IS_KEY _T("SOFTWARE\\ODBC\\ODBCINST.INI")
but it didn't function ... what I didn't understand on this sample is
#define IS_DISPLAY _T("DisplayName")
variable ?!
Thank you .
|
|
|
|
|
Flaviu 2 wrote: I try to read all ODBC installed on , with this sample , as with modify follow target :
#define IS_KEY _T("SOFTWARE\\ODBC\\ODBCINST.INI")
but it didn't function
Flaviu 2 wrote: what I didn't understand on this sample is
<SPAN class=code-preprocessor>#define</SPAN> IS_DISPLAY _T(<SPAN class=code-string>"</SPAN><SPAN class=code-string>DisplayName"</SPAN>)<BR> variable
?!
Your question is very unclear. See here perhaps.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Ok , here is situation :
#define IS_KEY_LEN 256
#define IS_DISPLAY _T("DisplayName")
#define IS_KEY _T("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall")
void CTestRegView::OnHelpReadodbc()
{
HKEY hKey = NULL;
DWORD dwIndex = 0;
LONG lRet;
DWORD cbName = IS_KEY_LEN;
TCHAR szSubKeyName[IS_KEY_LEN];
if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, IS_KEY, 0, KEY_READ, &hKey) != ERROR_SUCCESS)return;
while((lRet = ::RegEnumKeyEx(hKey, dwIndex, szSubKeyName, &cbName, NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
{
if(lRet == ERROR_SUCCESS)
{
HKEY hItem;
if (::RegOpenKeyEx(hKey, szSubKeyName, 0, KEY_READ, &hItem) != ERROR_SUCCESS)continue;
TCHAR szDisplayName[IS_KEY_LEN];
DWORD dwSize = sizeof(szDisplayName);
DWORD dwType;
if(::RegQueryValueEx(hItem, IS_DISPLAY, NULL, &dwType, (LPBYTE)&szDisplayName, &dwSize) == ERROR_SUCCESS)
{
TRACE("\n %s \n",szDisplayName);
}
::RegCloseKey(hItem);
}
dwIndex++;
cbName = IS_KEY_LEN;
}
::RegCloseKey(hKey);
}
this code , from above list all uninstall programs , but , if I change
#define IS_KEY _T("SOFTWARE\\ODBC\\ODBCINST.INI")
the code doesn't work ...then I ask myself , what is _T("DisplayName") which is paramenter 2 on ::RegQueryValueEx method ?
|
|
|
|
|
I found here[^] an solution ...
|
|
|
|
|
Hello,
i need some suggestions with this problem, after start my application does nothing until the user give some input to dialog.
but the cursor is always as "wait-cursor" showed!?
On Spy++ the only messages that are active are this wm_kickidle messages.
Now, this is only if my application runs on 64bit system (ms windows), not on 32bit???
Does any one have idea about how to solve this?
regards
arrin
|
|
|
|
|
I've declared an array like that in a header (the code should be a pure C code):
int someMap[MAPSIZE_X][MAPSIZE_Y];
and I want to use it as a global variable. The problem is if I include that header in another file I get a linker error that this variable was already defined and I'm really stuck here and I have absolutely no clue what's going on and how I'm missing the point.
If I use static it is fine but it isn't global any more.
"extern int gameMap[MAPSIZE_X][MAPSIZE_Y];" doesn't work as I'm expecting. I get the linker error even if I don't use the array in any files.
modified on Thursday, April 7, 2011 6:34 AM
|
|
|
|
|
In the header file declare it as extern int someMap[MAPSIZE_X][MAPSIZE_Y];
Give the declaration int someMap[MAPSIZE_X][MAPSIZE_Y]; in any one of the .cpp files.
|
|
|
|
|
Thank you for your reply.
Well, my code is supposed to be a C code.
|
|
|
|
|
Just replace CPP in my reply with C.
|
|
|
|
|
Thank you! It was a lame problem.
BTW Very interesting article.
|
|
|
|
|
int someMap[MAPSIZE_X][MAPSIZE_Y]; allocates memory for an array; if you include that statement in a header file, then include that header file in N different C files, you end up allocating N arrays, all with the same name, and the linker will complain as it can't have data blocks with global scope and conflicting names.
extern int someMap[MAPSIZE_X][MAPSIZE_Y]; says: "there is an array somewhere, but this by itself does not allocate it"; so inserting that in the header file tells your C files they get access to the array, without allocating memory at all, and without creating linker problems. Of course you still need a single int someMap[MAPSIZE_X][MAPSIZE_Y]; in one of the C files to actually allocate the memory; and that C file better also include the header file with the extern statement.
[ADDED]
One elegant way of dealing with all this is described in Stefan63's message below.
[/ADDED]
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Thursday, April 7, 2011 9:02 AM
|
|
|
|
|
Wow! Amazing explanation! Thank you so much!
|
|
|
|
|
you're welcome.
In software development, getting things to work may be the goal, understanding how each part works is a necessary step to get things to work reliably.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
If you have plenty of such variables or declarations you can use a macro to automatically use the declaration in your header file as a definition exactly once:
#ifndef GLOBALS_H
#define GLOBALS_H
#ifdef GLOBALS_C
# define MYGLOBAL_API
#else
# define MYGLOBAL_API extern
#endif
MYGLOBAL_API int someMap[MAPSIZE_X][MAPSIZE_Y];
#undef MYGLOBAL_API // clean up - we won't need that symbol outside this header
#endif
#define GLOBALS_C // MYGLOBAL_API will be resolved to empty string
#include "globals.h"
#include "globals.h"
Using this technique, adding another global variable just requires adding it to globals.h, you never have to touch globals.c (or any other file) for that purpose!
That said, it is always a good idea to keep the number of globals to a minimum, or, if possible, not use any at all. It's always very difficult to track an error that leaves a global in a bad state, because the problem may be caused anywhere in your program!
|
|
|
|
|
macros are wonderful when you know how to use them
|
|
|
|
|
That's very interesting thank you!
|
|
|
|
|
I am using vs2003
IN my Output window I got
No memory leaks detected.
Visual Leak Detector is now exiting.
Detected memory leaks!
Dumping objects ->
{379552} normal block at 0x12F15B10, 102 bytes long.
Data: < C|& * > B8 AE 43 7C 26 00 00 00 2A 00 00 00 01 00 00 00
{379550} normal block at 0x02327DB8, 102 bytes long.
Data: < C| * > B8 AE 43 7C 1F 00 00 00 2A 00 00 00 01 00 00 00
{339020} normal block at 0x02328150, 118 bytes long.
Data: <D : \ Myapp> 44 00 3A 00 5C 00 51 00 50 00 6C 00 75 00 73 00
Object dump complete.
Can any one tell me about this problem...
|
|
|
|
|
Define new as DEBUG_NEW and that would give you the line numbers of the memory allocation (that was not released properly).
Example:
#define new DEBUG_NEW
int main()
{
DWORD *pDW = new DWORD;
return 0;
}
Output without DEBUG_NEW defined:
Detected memory leaks!
Dumping objects ->
{317} normal block at 0x002CFC40, 4 bytes long.
Data: < > CD CD CD CD
Object dump complete.
Output with DEBUG_NEW defined:
Detected memory leaks!
Dumping objects ->
c:\users\rajesh r subramanian\documents\visual studio 2008\projects\test3\test3\test3dlg.cpp(9) : {317} normal block at 0x002DFC40, 4 bytes long.
Data: < > CD CD CD CD
Object dump complete.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Well, this is kinda maybe wrong name for a question, but... Here is what i need to do (i got no idea how, for now):
Here is a structure:
typedef struct _S
{
int a;
std::string b;
} S;
and here is a vector creation:
std::vector<S> Vec;
S s;
s.a = 1;
s.b = "hi";
Vec.push_back(s);
....
S s;
s.a = 10;
s.b = "something";
Vec.push_back(s);
So now there are 10 or something structures in a vector. The question is: I need to be able to update values of any of these structures, while they are still in their positions inside my vector. It is like, for example, i need to update string value in structure which has "a" integer = 10, so in this case in last inserted structure i need to change string value from "something" to, for example, "nothing". How to accomplish such thing? Or maybe i should use something else as a container and not a vector?
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Ok, i am so stupid =/. Completely forgot about good old iteration with "int i".
typedef struct _S
{
int a;
std::string str;
}
S;
int main( void)
{
std::vector<S> Vec;
S s;
s.a = 1; s.str = "hi";
Vec.push_back(s);
s.a = 2; s.str = "lol";
Vec.push_back(s);
s.a = 3; s.str = "nothing";
Vec.push_back(s);
std::vector<S>::iterator it;
for(it = Vec.begin(); it != Vec.end(); it++)
{
cout << it->a << " : " << it->str.c_str() << endl;
}
for(unsigned int i = 0; i < Vec.size(); i++)
{
Vec[i].str = "BOOM!";
}
for(it = Vec.begin(); it != Vec.end(); it++)
{
cout << it->a << " : " << it->str.c_str() << endl;
}
}
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
You can still use iterators
std::vector<S>::iterator it;
for(it = Vec.begin(); it != Vec.end(); it++)
{
cout << "Before: "<< it->a << " : " << it->str.c_str() << endl;
it->str = "New string value";
cout << "After: "<< it->a << " : " << it->str.c_str() << endl;
}
The iterator can be thought of as a pointer to your elements. There is no need to use indexing syntax just to update your data.
|
|
|
|
|
Thanks, thats correct. I am just still thinking in C
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi,
If the interger values are going to be unique then you can go for,
std::map<int, struct S>
Do your Duty and Don't expect the Result
|
|
|
|
|
Thanks, i'll check this one out
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
As an aside, you don't need a typedef with every struct definition - you can use the 'tag' of the struct in the same way you can use a class name.
Two options:
1. If you really only have an int that serves as soem sort of unique ID, and some value associated to that ID, then you should use a map rather than a vector. std::map automatically sorts your elements by your key values when you insert them. Retrieving an item is a simple and very fast operation.
2. If there's more to it, you can still use the std::find() method to locate a specific struct in your vector. You only need to define an equality operator for your struct like this: (not tested)
#include <vector>
#include <algorithm>
struct S {
int a;
std::string b;
bool operator==(const S& s) const {
return s.a==a;
}
S(int a_) : a(a_) {}
S(int a_, std::string b_) : a(a_), b(b_) {}
}
int main() {
std::vector<S> s;
s.push_back(S(1, "hi"));
s.push_back(S(10, "hello"));
std::vector<S>::iterator location = std::find(s.begin(), s.end(), 5);
std::string result;
if (location != s.end();
result = location->b;
}
You can check the online documentation on std::find() and std::find_if() for examples.
P.S.: anyone knows what is messing with code coloring here?
modified on Friday, April 8, 2011 2:40 AM
|
|
|
|
|