 |
|
 |
but when i try to compile it i get the next errors :
c:\program files\microsoft visual studio\vc98\include\rpcdce.h(30) : error C2146: syntax error : missing ';' before identifier 'RPC_BINDING_HANDLE'
c:\program files\microsoft visual studio\vc98\include\rpcdce.h(30) : fatal error C1004: unexpected end of file found
any idea why? (the rpcdce.h file exist)
thnaks
peleg
|
|
|
|
 |
|
 |
It's been a long time since I posted this article, and over a year since I've done any unmanaged C++ work, but my guess is that you need to get an updated version of the Windows SDK (or make sure you have the latest service pack for VC++. You're using 6.0, right?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
Hi, useful example (only one I could google!) of calling the APIs. Is there a reason for allocating the UUID on the heap (as opposed to as a local stack variable) or is it purely stylistic?
|
|
|
|
 |
|
 |
It's been quite a while since I wrote that code, but as I recall it was more of a style thing than anything else.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
What an a**hole. Relax...
Joel Humphrey
|
|
|
|
 |
|
 |
To what are you referring?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
I'm reading a large string with a few delimiters that allows me to determine names and values. For each of the names that are identified I place a new line character at the end of the string with the following code:
ename[I] = '\n';
My problem is when I go and try to read the element_name with this code:
for(ndx = 0; ename[ndx] != '\n'; ndx++)
{
if (ename[ndx] == ' ')
{
ndx++;
break;
}
}
I bypass where I place the \n
Can someone help?
|
|
|
|
 |
|
 |
That's NOT a very good way to constuct a for loop. First, you never EVER change the control variable (ndx) inside the loop. Last, the "for" statement should be something like
for (int ndx=0; ndx < somevalue; ndx++)
{
}
Without knowing more about the types you're using, I can't go any further.
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
|
|
|
|
 |
|
 |
If you use a function in rpcdce.h, you must also provide DCOM (you can download the necessary files from the microsoft site) to your Windows 95/98 users.
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
template<unsigned int size = 32>
class uuid_string
{
public:
uuid_string()
{ generate();
}
operator const TCHAR*()
{ return string_;
}
void generate()
{ ZeroMemory(string_, sizeof(TCHAR) * (size + 1));
unsigned long count = size;
while(count)
{
UUID u;
UuidCreate(&u);
TCHAR* us = NULL;
if(RPC_S_OK == UuidToString(&u, &us) && us && *us)
{
TCHAR* khar = us;
while(*khar && count)
{
if(*khar != _T('-'))
{ string_[size - count] = *khar;
--count;
}
++khar;
}
RpcStringFree(&us);
}
else
{ count = 0;
}
}
}
private:
TCHAR string_[size + 1];
};
#pragma comment(lib, "rpcrt4")
|
|
|
|
 |
|
 |
John, just to add for completeness
CString CClassItem::GetGUID()
{
CString strGUID;
LPOLESTR wszCLSID = NULL;
StringFromCLSID(m_guid, &wszCLSID);
int nLen = lstrlenW(wszCLSID);
TCHAR* szCLSID = new TCHAR[nLen + 1];
#ifndef _UNICODE
wcstombs(szCLSID, wszCLSID, nLen);
szCLSID[nLen] = 0;
#else
lstrcpy(szCLSID, wszCLSID);
#endif
CoTaskMemFree(wszCLSID);
strGUID = szCLSID;
delete szCLSID;
return strGUID;
}
Normski. - Professional Windows Programmer
|
|
|
|
 |
|
 |
You probably missed the function calls to make GUID first..
GUID m_guid;
::CoCreateGuid(&m_guid);
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
 |
|
 |
Well spotted!
I clipped the code snippet from our production code and in the constructor it calls
::CoCreateGuid. 10/10 for observation
Normski. - Professional Windows Programmer
|
|
|
|
 |
|
 |
Win32 API GetTempFileName()
Crivo
Automated Credit Assessment
|
|
|
|
 |
|
 |
But I needed something that was *guaranteed* to be unique *every time* the filename is generated. You can't do that with GetTempFileName.
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
Under what situations is GetTempFileName not unique?
A proposed name is derived. If the file exists, the number portion is incremented until you do get a unique filename.
|
|
|
|
 |
|
 |
If the file exists
And if it doesn't? You run the risk of non-unique names.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
 |
|
 |
If the file got deleted, what does it matter if another one gets created with the same name?
Maybe if an example of the situation requiring an absolute, never used, unique filename were presented it would make more sense.
|
|
|
|
 |
|
 |
You're assuming that the files will get deleted. In my particular situation, that's not a safe assumption to make.
Why does my need for a unique filename have to make sense? I briefly explained in the article the reason I had to come up with this code, and then, that I thought it might be useful to others. I could have sworn that I read someplace that this is what CodeProject is for (sharing code).
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
Don't get me wrong; I like your code!
I'm just concerned about a major project I have that relies on GetTempFileName()! I wanted to know what the shortcomings were in using it!
|
|
|
|
 |
|
 |
The filename that GetTempFileName creates is only unique for the directory its called with. If you have a multithreaded/multiuser system the function could return the same filename twice, even if the probability is low. If you use an UUID the filename will be unique in any directory on any computer on any network. Well, at least in theory.
// Dalle
|
|
|
|
 |
|
 |
The API does NOT *guarantee* a unique file name when using GetTempFileName. I need the *guarantee* that the filename will be unique. The *only* way to do this is to use a UUID as a basis for the name.
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
 |
|
 |
Here's what I see in the MSDN documentation
If uUnique is zero, the function uses a hexadecimal string derived from the current system time. In this case, the function uses different values until it finds a unique filename, and then it creates the file in the lpPathName directory.
Looks pretty unique to me. Again, I might be missing something. (And I have a major project riding on this )
I need to prove that this is a problem before management will approve such a drastic change.
|
|
|
|
 |
|
 |
Brad,
The problem is that GetTempFileName checks to see if the file exists in the directory you specify before returning the "unique" name. The caveat here is that GetTempFileName does not actually create the file for you.
So, if you get multiple file names using this function, but do not create the files between calls, how is the function to know that a given name has not already been used?
Only use GetTempFileName when you plan to create the file immediately upon the function call's return, and only if the application is not multithreaded, or running on multiple machine using a common storage point for the temporary files.
--
Paul
"I drank... WHAT?"
|
|
|
|
 |
|
 |
Paul A. Howes wrote:
The caveat here is that GetTempFileName does not actually create the file for you.
According to MSDN and what I've seen...
If uUnique is zero, the function uses a hexadecimal string derived from the current system time. In this case, the function uses different values until it finds a unique filename, and then it creates the file in the lpPathName directory.
|
|
|
|
 |