|
Put the L back in front of the "WQL" string - ExecQuery() is expecting a Unicode string, which is what the 'L' specifies.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
In trying that i still get an error
the error is....
error C2664: 'ExecQuery' : cannot convert parameter 2 from 'class CString' to 'unsigned short *const '
my code is......
CString strIPAddress = "127.0.0.1";
CString strQuery;
strQuery.Format("SELECT * FROM Win32_PingStatus WHERE Address = %s", (LPCTSTR) strIPAddress);
hres = pSvc->ExecQuery(L"WQL", strQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator);
|
|
|
|
|
keithlee wrote: strQuery.Format("SELECT * FROM Win32_PingStatus WHERE Address = %s", (LPCTSTR) strIPAddress);
hres = pSvc->ExecQuery(L"WQL", strQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator);
strQuery.Format(_T("SELECT * FROM Win32_PingStatus WHERE Address = %s"), (LPCTSTR) strIPAddress);
hres = pSvc->ExecQuery(_T("WQL"), strQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator);
Does this help?
Nibu thomas
Software Developer
|
|
|
|
|
that shows the followng error
error C2664: 'ExecQuery' : cannot convert parameter 1 from 'char [4]' to 'unsigned short *const '
|
|
|
|
|
Have you done any Unicode programming? You need to convert your string to Unicode. Include the atlconv.h file and do this:
CString strIPAddress = _T("127.0.0.1");
CString strQuery;
strQuery.Format(_T("SELECT * FROM Win32_PingStatus WHERE Address = %s"), (LPCTSTR) strIPAddress);
hres = pSvc->ExecQuery(L"WQL", T2W(strQuery), WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator); This will ensure that all the strings are of the correct type and should work nicely.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
hi
no luck there with the above code, any idea whats wrong?
i get the following errors....
error C2065: '_lpa' : undeclared identifier
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
error C2065: '_convert' : undeclared identifier
|
|
|
|
|
just found the problem, did a look up on MSDN and you need to specify
USES_CONVERSION;
wohoo, finally it works!
|
|
|
|
|
|
SWDevil wrote: how can I do this?
Read the file into a CString object, then use the Find() method.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
|
|
does CFile::Read()return a CString obbject (I don't have MSDN at the moment, that's why I'm asking)
DavidCrow wrote: Just take what is between >> and <<.
How do I do that? with Right/Left functions?
|
|
|
|
|
If you use a CStdioFile you can use the ReadString() function to read the line directly into a CString.
ReadString(input);
then you can do the find on your input
int endtag = input.Find(">>", 0);
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
|
|
|
|
|
Oh yeah and the function you want to use for getting that 12345 is the Mid() function.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
|
|
|
|
|
<code>
typedef struct alcPacket
{
char workStationID[20];
char NTLogin[20];
}*alcPacket_t;
</code>
Sender :
<code>
alcPacket_t alcp;
strcpy(alcp->NTLogin,"xyz");
strcpy(alcp->workStation,"yahoo");
nRet = sendto(hSocket,(char*)alcp,sizeof(alcPacket),0,(struct sockaddr*)&stDstAddr,sizeof(stDstAddr));
</code>
Receiver :
<code>
alcPacket_t alcp;
nRet = recvfrom(hSocket,achInBuf,120,0,(struct sockaddr*)&stSrcAddr,&addr_size);
alcp = (alcPacket_t)achInBuf;
printf("%s",alcp->NTLogin);
printf("%s",alcp->workStationID);
</code>
Everthing works fine.. but i get a the output for NTLogin is preceded by a long streak of ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌxyz
the out put looks like
ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌxyz
Yahoo
ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌxyz
yahoo
how can i remove that junk from NTLogin? what's wrong?
VuNic
|
|
|
|
|
Have you tried
ZeroMemory(alcp, sizeof(alcp);
and then send it?
mfg
Phil
bum... and I thought I´d got rid of all the bugs
|
|
|
|
|
VuNic wrote: alcPacket_t alcp;strcpy(alcp->NTLogin,"xyz");
This looks suspicious. Try:
alcPacket_t alcp;
alcp = new alcPacket;
strcpy(alcp->NTLogin, "xyz");
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
sorry for late reply David, just got into this(sock) module in a round robin fashion. hmm but the problem is still there.
i have some fundamental doubt :
<code>
typedef struct alcPacket
{
char workStationID[20];
char NTLogin[20];
}*alcPacket_t;
</code>
Why the sizeof alcPaket shows 120 ?
and in the receiving end, tested the strlen for the
<code>
nRet = recvfrom(hSocket,achInBuf,120,0,(struct sockaddr*)&stSrcAddr,&addr_size);
alcp = (alcPacket_t)achInBuf;
printf("\n%s",alcp->NTLogin);
printf("\n%d",strlen(alcp->NTLogin));
printf("\n%s",alcp->workStationID);
printf("\n%d",strlen(alcp->workStationID));
</code>
It prints the values as
48 for NTLogin WRONG, with that junk characters
11 for Workstation ID.RIGHT
what could be the problem ??
VuNic
|
|
|
|
|
OOOOOOOOPS, i'm really sorry David. it was a GIGO,
i made a worst mistake.. at the sending End,
i have the given the structure as
<br />
typedef struct alcPacket<br />
{<br />
char workStationID[60];<br />
char NTLogin[60];<br />
<br />
}*alcPacket_t;<br />
But while receiving, i used the strcut,
<br />
typedef struct alcPacket<br />
{<br />
char workStationID[20];<br />
char NTLogin[20];<br />
<br />
}*alcPacket_t;<br />
look at char workStationID[60]; andchar workStationID[20];
the size is 60 in the former and the size is 20 with the later.
......sorry for the strain i have made to your mind .............................
VuNic
|
|
|
|
|
VuNic wrote: ......sorry for the strain i have made to your mind .............................
Mine tooo .. Seen your mail today only... i am don't have access to internet on client site..
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
ohh, just checked your reply alok. never mind, no problem. i wish you have a good time in pune. take care. bye
VuNic
|
|
|
|
|
I just need pointing in the right direction. I've used CFileDialog successfully to open files and read the contents (NB: do I need to specifically close an ifstream, or will it be done automatically once it goes out of scope?)
I've also edited this so that a "Save as" dialog comes up. But I'm not sure what the proper way to then write to this file. I've set the PROMPTOVERWRITE flag like this
CFileDialog fileBrowser(FALSE,".csv",NULL,OFN_OVERWRITEPROMPT,"Comma Separated Value Files (*.csv)|*.csv|",NULL);
int ret = fileBrowser.DoModal();
if(IDOK == ret) then write stuff to the file
so I want to know the proper way to write data to this file, presumably using an ofstream? do i then need to set ios::trunc to make sure if they overwrite the file it erases the old contents properly?
I can probably make this work, I just wanted to make sure I wasn't being a complete muppet
tia
|
|
|
|
|
ldsdbomber wrote: I want to know the proper way to write data to this file
Well, you should know, your're designing the application and the file structure. Right?
Seriously, what do you mean by "proper"?
Just to be sure:
The CFileDialog class is simply for getting a filename and a path to a file that you either wants to read or write. The CFileDialog class does not perform any read or write operations on the file selected by the user. The OFN_OVERWRITEPROMPT flag only instructs the CFileDialog to warn the user if you opened a "SaveAs" dialog and the user selected an existing file. It has nothing to do with how the file is opened later.
BTW, you need an extra '|' at the end of your filter string.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Hi All,
I have created a window using the Win32 api functions. Now I created a message loop inside a member function of the class like so:
{<br />
UINT uMsg = 0;<br />
<br />
while (true)<br />
{<br />
if (::PeekMessage ((LPMSG) (&uMsg), m_hWnd, 0, 0, PM_REMOVE))<br />
{<br />
::TranslateMessage((LPMSG) (&uMsg));<br />
::DispatchMessage((LPMSG) (&uMsg));<br />
}<br />
else<br />
{<br />
if (MessageQueueEmpty () == FAILURE)<br />
{<br />
return FAILURE;<br />
}<br />
}<br />
}<br />
<br />
return SUCCESS;<br />
}<br />
However after the first iteration, this becomes NULL . If I make uMsg static, it works fine.
Why??
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
-- modified at 10:24 Thursday 2nd March, 2006
|
|
|
|
|
This code has a few problems. Here’s is an edited down version of your code which shows the biggest:
UINT uMsg = 0;
::PeekMessage((LPMSG)(&uMsg), m_hWnd, 0, 0, PM_REMOVE)
The first parameter to PeekMesage is a LPMSG but your variable is of type UINT . You would get a compiler error if you tried the following code:
::PeekMessage(&uMsg, m_hWnd, 0, 0, PM_REMOVE)
You "solve" this by adding the following C-style cast:
(LPMSG)
This will never work, all you've done with this cast is say to the compiler, "Yeah I know a LPMSG isn't the same as a UINT* and you normally wouldn't compile this code but I'm the man, just blindly push ahead and compile it anyway". The problem is a UINT isn't a MSG , cast or no cast.
Here's what it should look like (edited down version):
MSG m;
::PeekMessage(&m, m_hWnd, 0, 0, PM_REMOVE)
A word of advice:
Never use C-style casts (a type in brackets). Always use function style casts instead. When you find yourself tempted to write (UINT)i write static_cast<UINT>(i) instead. If the cast doesn't make sense the compiler will complain (you can still get into trouble but the chances are a lot less). If you want to make the compiler do what you say as a C-style cast does use a reinterpret_cast . Casts are ugly (but occasionally necessary) and generally indicate a design flaw. The function style casts syntax allows you to spot casts more easily. Also C-style casts are not fine grained enough where as function style casts come in four types: dynamic_cast , static_cast , reinterpret_cast , const_cast so it is clearer and harder to abuse.
Steve
|
|
|
|
|