|
Use strtol(..., 16) or strtoul(..., 16) .
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Ahh.. Thanks. It worked perfectly!
|
|
|
|
|
You could use a function such as this:
BYTE HexToByte(LPCSTR cpHex)
{
BYTE cRetVal;
if (*cpHex < 58)
cRetVal = *cpHex - '0';
else
cRetVal = *cpHex - '7';
cRetVal <<= 4;
cpHex++;
if (*cpHex < 58)
cRetVal += *cpHex - '0';
else
cRetVal += *cpHex - '7';
return cRetVal;
}
onwards and upwards...
|
|
|
|
|
strtol(..., 16) or sscanf(str, "%X", &myInt)
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi All,
I have successfully automated MSWord with VC++. Now what I need to do is open an *.doc file and perform searching of some particular words in that file .How I can perform it in my programme .
Please Help me
Thanks in Advance
George K Jolly
-- modified at 12:16 Wednesday 2nd August, 2006
|
|
|
|
|
Post the code you've used to automate word.
|
|
|
|
|
For Automation Just see the link
http://support.microsoft.com/kb/178749/E-US/
|
|
|
|
|
DWORD retval;
LPWSTR domaincontroller = NULL;
LPUSER_INFO_3 buffer = NULL;
NET_API_STATUS nStatus;
WCHAR *uni_domain = NULL;
WCHAR *uni_username = NULL;
uni_domain=L"Elko";
uni_username=L"richardb";
ofstream outValues;
outValues.open("ValidUserName.txt",ios::out);
outValues << uni_domain << endl;
outValues << uni_username << endl;
// This nStatus returns a true. But if I comment this part out.....
nStatus = NetGetDCName(NULL, uni_domain, (LPBYTE *)&domaincontroller);
if(nStatus != NERR_Success){
retval = NULL;
return false;
}else{
return true;
}
if(domaincontroller == NULL){
retval = NULL;
return false;
}else{
return true;
}
.... the "second" nStatus returns false. The NetUserGetInfo funtion is giving me alot of problems.....
nStatus = NetUserGetInfo(domaincontroller, uni_username, 3, (LPBYTE*)&buffer);
if(nStatus != NERR_Success){
retval = NULL;
return false;
}else{
return true;
}
.... can anyone plz help
Thanx in advance
Regards
Programm3r
|
|
|
|
|
Programm3r wrote: .... the "second" nStatus returns false.
So what's the problem? If NetUserGetInfo() is returning 0 , then it was successful.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have 3 Questions.
1. Why a size of an empty class is 1 byte?
2. if this code executes, again the size of class is 1 byte (padding not occuring even padding size is 4)
class MyClass
{
char i;
};
MyClass m;
printf("%d",sizeof(m));
3. for this code it will print 8 bytes as size (default padding 4 bytes)
class MyClass
{
int i;
char i;
};
MyClass m;
printf("%d",sizeof(m));
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
Sarath. wrote: 1. Why a size of an empty class is 1 byte?
Because the standard requires it to be so. Basically, it is so you avoid problems where you try to allocate 0 bytes of memory (ever try to do int* pi = new int[0] ?). If an empty class is always at least 1 byte, then you can't have that problem.
Sarath. wrote: 2. if this code executes, again the size of class is 1 byte (padding not occuring even padding size is 4)
The padding for characters is 1 byte. If that is all that is in your class, then it won't bother padding it since it is almost guaranteed to be placed on a byte boundary.
Sarath. wrote: 3. for this code it will print 8 bytes as size (default padding 4 bytes)
This actually occurs because the compiler packs extra characters for you (if you use pragma pack, you avoid this). Since you have more than just your character now, it places enough memory for your class to end on a double word boundary. This makes it more efficient if you declare an array of these objects since the integer values will be guaranteed to be on the proper boundaries in memory.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks alot for your reply. it was quite informative.
one more question which has been raised when I read your answer
int* p1 = new int[0];
*p1 = 10;
printf("%d",*p);
delete p1;
In the above code, printing of the above code will work fine. but delete fails.
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
Sarath. wrote: int* p1 = new int[0];
That line will actually cause a memory corruption. It has been mentioned that the compilers should treat this as an error when the new standard is released, but if you try it on certain compilers right now, it won't give you an error. If you do it with Microsoft's compiler, you usually get a weird looking message box that pops up and tells you that the memory has been corrupted.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Anyway it's returning a valid pointer. my question was, will this create a memory leak? (if we don't call delete.anyway if we call delete it will fail)
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
Sarath. wrote: Anyway it's returning a valid pointer
No, its not valid pointer.
operator new allocates additional memory on heap , when we use it. It contains header info and bytes to guard off memory, called 'No Mans land'.
So actual size will be,
actual_size=sizeof(headerinfo)+nSizeRequestedbyUs+NOMansLandSize
In above case though nSizeRequestedbyUs is 0, it returns valid address, but not supposed to access by us.
Sarath. wrote: will this create a memory leak? (if we don't call delete.anyway if we call delete it will fail)
Yes.
By accessing it we are corrupting it. So giving error while deletion.
If you try to delete it without accessing it , ie. without assigning any value to it, it will not give you error.
-- modified at 2:57 Thursday 3rd August, 2006
|
|
|
|
|
Sarath. wrote: Anyway it's returning a valid pointer.
On the VC6 compiler, the line with new int[0] would cause an immediate crash in both release and debug builds. I'm not sure if the newer compilers still do that, but the line is invalid code. If the pointer that comes back looks valid, I assure you, it isn't. You are guaranteed to corrupt your memory by writing to the location it gives you.
Sarath. wrote: my question was, will this create a memory leak?
You won't get a memory leak, you get memory corruption. Basically, the line itself causes a problem, and deleting it is the least of your worries (calling delete won't fix the memory problem you created by trying to declare a 0-sized array).
In general, think logically when programming. It makes no sense to have an array with no capacity; therefore, it is not valid to declare.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Sarath. wrote: 1. Why a size of an empty class is 1 byte?
See here.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have a dialog based app and would like to have another dialog be anchored to either the bottom or the left side of my main dialog. Can someone please point me to some code for this, or help me? I figured I should be using SetWindowPos(), but how do I know where to place it?
Thanks in advance.
|
|
|
|
|
- Handle the
WM_MOVE notification in your main dialog.
- Compute your main window's bottom-L corner.
- Call
MoveWindow() or SetWindowPos() on the secondary dialog. /ravi
|
|
|
|
|
IN addition to Ravi's reply, you may have to use modeless dialog
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
yes, I'm sorry. The second dialog I am trying to use is a modeless dialog that is show when a menu item is selected.
can someone help me calculate the size of my main dialog?
|
|
|
|
|
GetClientRect and GetWindowRect are at your disposal
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
NYTSX wrote: calculate the size of my main dialog?
GetWindowRect()
/ravi
|
|
|
|
|
I have a many C++ windows projects, dlls and librarys. I have done some research to find out what happens if there are similar string IDs in projects, dlls and libraries after they are are linked together.
What happens is the string in the project always replaces the string in the dll or library if there is a string ID match.
Example: I declare string ID 100 as "Chris" in the project, "John" in the dll, and "Bob" in the library. I use CString::LoadString(100) in the dll and CString::LoadString(100) in the library. When these two statements are executed the string "Chris" is loaded from the project string table and not the library and dll.
I was able to solve the similar string issue between projects and dlls useing ::FindResource along with the dlls instance. Has anyone figured out how to have similar strings between projects and libraries?
Chris
|
|
|
|
|