|
Hi all,
I need to compare 2 strings,one is a simple character string and the other is a LPWSTR value.How can I do it.Is there any type conversion available.
Thanks
Abhishek.
Learning is a never ending process of Life.
|
|
|
|
|
You will need to convert one of the strings into the same format as the other. Which one you choose does not matter.
Use one of these functions:
MultiByteToWideChar
WideCharToMultiByte
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!
|
|
|
|
|
Isn't it best to convert the single-byte to wide-format? If conversion from wide- to single-byte format looses information (because some widechars are not representable), the strings might match after conversion, even if they don't actually match... No?
|
|
|
|
|
example:
USES_CONVERSION;
LPCSTR s1 = "Hello World!";
LPCWSTR s2 = L"Hello World!";
int i = _tcscmp(A2CT(s1), W2CT(s2));
There is other ways, but more complicated.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Good day all
I was wondering if someone could help with this. I need to find a way of checking to see that if my application that I built is currently running? Any information would be a great help.
Thanks.
|
|
|
|
|
Just use the prevInstance member value of the App object.
If (App.prevInstance) Then
MsgBox "This is the second instance of your app"
End If
When you run your program, the first time, nothing will happen, the second time you will get a message box indicating that there is a previous instance of your app running.
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!
|
|
|
|
|
I wanna find my articles which I wrote in this fourm some days ago ,how could I do that?thx
YES, I am here.
|
|
|
|
|
You mean old forum posts?
Look at the top of the page on the left, under the Options it should display your username. Click on that to get to your profile page.
From there, click the "Messages Posted" link, and it'll show all the posts you've made
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
u can try to search for it, using the search in the top of the thread page on the right if u know ur name is enough!
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
It seems that I could not find with set my name as the keyword in this fourm.
YES, I am here.
|
|
|
|
|
My custom database class has this destructor:
~DbClass()
{
Close();
m_pConn.Release();
m_pConn = NULL;
m_strConnection = _T("");
<code> if(m_pConnPhoto )
{
if(m_pConnPhoto->GetState() != ADO::adStateClosed)
m_pConnPhoto->Close();
}
m_pConnPhoto.Release();
m_pConnPhoto = NULL;
m_strConnection1 = _T("");</code>
::CoUninitialize();
}
I added the stuff in red to a preexisting sample, so I'm not sure if it looks okay.
Anyways I made a MyDBClass m_db variable in the doc of my mfc mdi app. So far I havent deleted (??) it anywhere. Not even sure if I need to destroy or delete it, or take care of it somehow...
What do you think?
Thanks,
ns
|
|
|
|
|
for every new there's a delete somewhere...else there's no need I feel. If you need a delete put it in the CMyAppDoc::OnCloseDocument() override.
|
|
|
|
|
Hi all,
I want to use IDiskQuotaControl interface to set per user quota on a network shared volume. But I need include the lib into my project which implement the interface.
Which lib is that?
Thanks for your answer.
Laura
|
|
|
|
|
You don't need a specific lib, CoCreateInstance with CLSID CLSID_DiskQuotaControl should work.
Look! They have the Internet on computers now! (Homer J. Simpson)
|
|
|
|
|
I tried, but always got link error 2001:
Execution.obj : error LNK2001: unresolved external symbol _CLSID_DiskQuotaControl
Execution.obj : error LNK2001: unresolved external symbol _IID_IDiskQuotaControl
|
|
|
|
|
try __uuidof(DiskQuotaControl) and __uuidof(IDiskQuotaControl) instead.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Yes I find a sample code for this.
just add #define INITGUIDS
(like _uuid())
Thanks you all.
|
|
|
|
|
Hello there,
How can i make a Right aligned RichEdit box, programically ??
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi,
I have some problem with this query i execute under visual C++6.0
"SELECT Nom, CodePostal, Sum(Montant) AS MontantRemb, DateTraitement <br />
FROM TClient GROUP BY Nom, CodePostal, Montant,DateTraitement <br />
HAVING (((DateTraitement)=#09/05/2002#));"
In Microsoft Access interface it work well but if i execute it via ODBC like this :
retcode = SQLExecDirect(m_hstmt,(SQLCHAR*)strSQL, SQL_NTS);
this isntruction work also but i have a problem with SQL Fetch:
while (( retcode = SQLFetch(m_hstmt))!= SQL_NO_DATA)<br />
{ <br />
SQLGetData(m_hstmt, 1, SQL_C_CHAR, szNomClient, 25, &cbName);<br />
SQLGetData(m_hstmt, 2, SQL_C_CHAR, szCodePostal, 6, &cbName);<br />
SQLGetData(m_hstmt, 3, SQL_C_CHAR, szMontant, 16, &cbName);<br />
SQLGetData(m_hstmt, 4, SQL_C_CHAR, szDateTraitement, 11, &cbName);<br />
} Here retcode return 100 and i can't obtain my data
Thanks in advance for any help
|
|
|
|
|
Are you sure your datatypes in the calls to SQLGetData() are correct? Your select statement has column #3 as Sum(Montant). Without knowing your table structure, I'm guessing Montant is a numeric field, in which case you'll want to use something like SQL_C_ULONG with a size of 4 bytes. Your date field, the 4th column, would also have a problem. That should go with SQL_C_TYPE_TIMESTAMP, assuming it's stored as a date field in your table and not a string. SQL_C_CHAR is only used for character (string) columns.
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
Hello,
I am trying to pass a file through a Socket plus I would like to send the name of the file also.. Here is my source for sending the file. (I'll tell you my problem at the end)
void CClientDlg::OnBAttach()
{
CSocket* cSocket = new CSocket();
cSocket->Create();
cSocket->Connect((LPCTSTR(m_strServerIP)),m_iFtPort);
static char BASED_CODE szFilter[] = "All Files (*.*)|*.*||";
CString strPath;
CFileDialog m_ldFile(TRUE,".*",strPath,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
m_ldFile.m_ofn.lpstrInitialDir = _T("C:\\");
if (m_ldFile.DoModal() == IDOK)
{
strPath = m_ldFile.GetPathName();
CFile myFile;
myFile.Open(strPath, CFile::modeRead | CFile::typeBinary);
long nRead;
do
{
byte* data = new byte[4096];
nRead = myFile.Read(data, 4096);
cSocket->Send(data, nRead);
delete data;
}
while (nRead > 0);
myFile.Close();
}
cSocket->Close();
delete cSocket;
}
And for my Receive function on the "Server" side
long nRead;
do
{
byte* data = new byte[4096];
nRead = pSocket->Receive(data, 4096);
m_destFile.Write(data, nRead);
delete data;
}
while (nRead > 0);
I can't figure out a good way to get the file name, plus when I receive the file like this, sometimes the file ends up a few bytes longer than the source(sending) file and sometimes the file comes across perfect..
On my accept function I create a pre defined file for receiving and I open it for reading.. then in my receive I start writing to the file. When the client disconnects I close the file.. This just doesn't seem like a good way to pass files through a socket.. anyone have any better ways of doing this. I have been beating my head against the wall for days. I can't find any examples on MSDN and I found only 1 example at codeguru.com
Thanks for any suggestions.
Rob
|
|
|
|
|
To send across the file name, you could prepend the file's data with the file's name in a header struct, which appears to be what you were starting to do. Your receive code would have to be more intelligent in this case... instead of just dumping whatever it receives over the socket into a file, you'd have to look for the header first and then continue on.
It's important that your receive code only pulls in the header initially, and that it doesn't spill over into the file data. That's what
nRead = pSocket->Receive( byBuffer + nPos, sizeof( FileHeader ) - nPos );
nPos += nRead;
</code>
is doing in the following pseudo code. It will only read at a maximum sizeof( FileHeader ) bytes. You can't assume that you'll get all of those bytes in one pass, however, which is why you still have to put it in a do..while.
typedef struct
{
char szFileName[_MAX_PATH];
} FILE_HEADER, *LPFILE_HEADER;
send_code()
{
... Get the file name
#define BUFFER_SIZE 4096
long nRead = 0;
BYTE byBuffer[BUFFER_SIZE];
FILE_HEADER FileHeader;
strcpy( FileHeader.szFileName, myFile.GetFileName() );
cSocket->Send( dynamic_cast< LPVOID >( &FileHeader ), sizeof( FileHeader ));
do
{
nRead = myFile.Read( byBuffer, BUFFER_SIZE );
cSocket->Send( byBuffer, nRead );
} while( nRead > 0 );
... clean up
}
receive_code()
{
long nRead = 0;
long nPos = 0;
BYTE byBuffer[BUFFER_SIZE];
FILE_HEADER FileHeader;
do
{
nRead = pSocket->Receive( byBuffer + nPos, sizeof( FileHeader ) - nPos );
nPos += nRead;
} while( (nPos < sizeof( FileHeader )) && (nRead > 0) );
if( nPos != sizeof( FileHeader ) )
{
return;
}
... create file with FileHeader.szFileName
do
{
nRead = pSocket->Receive( byBuffer, BUFFER_SIZE );
destFile.write( byBuffer, nRead );
} while( nRead > 0 );
}
</code>
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
why not use archives to simplify things?
Sending code would be
<br />
CSocket cSocket;<br />
cSocket.Create();<br />
cSocket.Connect((LPCTSTR(m_strServerIP)),m_iFtPort);<br />
<br />
CSocketFile sf(&cSocket);<br />
CArchive ar(&sf, CArchive::store);<br />
<br />
<br />
strPath = m_ldFile.GetPathName();<br />
CFile myFile(strPath,<br />
CFile::modeRead | CFile::typeBinary); <br />
<br />
DWORD length = myFile.GetLength();<br />
char *data = new char[length];<br />
myFile.Read(data, length);<br />
<br />
ar << myFile.GetFileName();<br />
ar << length;<br />
ar.Write(data, length);<br />
<br />
delete[] data;<br />
myFile.Close(); <br />
and on the receiving side, just the reverse process
<br />
CSocketFile sf(pSocket);<br />
CArchive ar(&sf, CArchive::load);<br />
<br />
CString filename;<br />
ar >> filename;<br />
CFile m_destFile(filename,<br />
CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);<br />
<br />
DWORD length;<br />
char *data;<br />
<br />
ar >> length;<br />
data = new char[length];<br />
ar.Read(data, length);<br />
<br />
m_destFile.Write(data, length);<br />
m_destFile.Flush();<br />
<br />
delete[] data;<br />
m_destFile.Close();<br />
I don't know about the do..while for the Read/Write though, this code is working fine for me
Bilal Naveed
|
|
|
|
|
Thanks to both of you for replying so fast and providing source code!! While I was waiting for a post I implemented CreatFile and TransmitFile, this worked but I haven't sent across the filename.. I think I will play around with the code you 2 provided to see what method I like best.
Thanks alot!!
Rob
|
|
|
|
|
I am going to use the code you provided me. Thanks again!! one last question do you know of a way to see the progress of the ar.Write and ar.Read.. When sending files like this across the internet the process can take some time, it would be nice to see progress if possible.
Thanks again for all your help!
Rob
|
|
|
|
|