|
-
Dec 4th, 2001, 08:48 AM
#1
Thread Starter
New Member
CString::GetLength
Hello,
I've a quick question:
How can I determen the length of a string passed from a VB program. I started out with a verry simple function that returns the lenth of a string. (The equvilant of Len() in vb). But it does'nt work.
int test(CString input)
{
return input.GetLength();
}
and the VB code:
Declare Function test Lib "myDll" (ByVal str As String) As Integer
Private Sub Command1_Click()
MsgBox test("1234")
End Sub
The result is a messagebox containing "-6038" ?!?!?!?
I'm (developing) with Embedded visual studio 3.0
-
Dec 4th, 2001, 09:47 AM
#2
You can't use a CString object as parameter. You need LPSTR (or char* if you prefer that).
Code:
int test(char* input)
{
CString strInput(input);
return strInput.GetLength();
}
and the vb must be:
Declare Function test Lib "myDll" (ByVal str As String) As Long
Integer in VB is 16 bits long, in Windows C it is 32 bit.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 4th, 2001, 10:48 AM
#3
Thread Starter
New Member
Got it working :) tanks
hmm, it is working now. LPSTR did'nt work, but LPCWSTR did 
int test(LPCWSTR input)
{
CString strInput(input);
return strInput.GetLength();
}
It seems that the passed string is a Unicode String or something. 2 bytes per character.
maybe there is a difference between Embedded VB and VB.
-
Dec 4th, 2001, 02:32 PM
#4
Thread Starter
New Member
assign value
Ok that It works 
But now:
How can I assign a value to the string? I'm trying to read a part of a file:
(this does'nt work)
WORD readString (WORD fileIndex,LPWSTR input,WORD len)
{
int readCount;
unsigned short *readBuffer;
CString strInput(input);
if(files[fileIndex].open)
{
if(len > inpBufSize) len=inpBufSize;
readBuffer=strInput.GetBuffer(len);
readCount = files[fileIndex].file.Read(readBuffer,len);
return readCount;
}
else return -1;
}
My function to write a vaulue allready works:
void writeString (WORD fileIndex, LPCWSTR string)
{
CString strInput(string);
// Create a storing archive.
CArchive arStore(&files[fileIndex].file, CArchive::store);
arStore.WriteString(strInput);
}
-
Dec 4th, 2001, 03:19 PM
#5
Monday Morning Lunatic
Why are you bringing MFC into this? Surely it's simpler just to stick with the standard C (or if you want, C++, but be careful with your function names) libraries to do all this? They can do it smaller than MFC can
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|