Jump to content

VB Strings

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
reniery

reniery

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
I've been working in integrating my vb6 app with a scanner and have come upon a small problem. I´m using the dll´s provided by the scanner manufacturer.

Ok what i'm trying to do is pass a string variable to a dll.

This is from the sdk documentation

To set a string, use a pointer to the string.
To get the string, allocate 256 bytes of memory and
set a pointer to that memory. The string is copied
to the memory.


This I think is my problem

strTemp="test"

 ScannerPrint STRING, StrPtr(strTemp)

Using this the only thing passed to the dll is the first letter in this case ´t´.
The reason is cause strptr only returns the adress in memory of the first char in the string so how do I pass the whole string.

Help please :confused:

#2
mbshinde78

mbshinde78

    Newbie

  • Members
  • PipPip
  • 19 posts
Have you tried using &strTemp instead?

#3
reniery

reniery

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
No I haven't tried &strtemp, but I'll try it right now.

Btw I found the solution for my problem, I used a c++ dll and then I just call it from my vb app. But is there a way to do this in vb6 directly, this are the functions I did in my c++ dll




BSTR __stdcall testFunction(BSTR stringVar)

{

             LPSTR buffer;

	buffer = (LPSTR)stringVar;

	

	if (OK!=SETDRIVERPAR(290,(LPARAM)buffer)){

	::MessageBox(NULL,"Error asignando ","Error",0);

	}

	else{

	

	}


	//buffer = _strrev(buffer);

	return(SysAllocString(stringVar));


}


BSTR __stdcall testGetSerial()

{

	unsigned char bufSerial[255];

	if (OK!=GETDRIVERPAR(290,(LPVOID)bufSerial)){

             ::MessageBox(NULL,"Error retrieving Serial ","Error",0);

	} 

	else{

	}


	return (BSTR)bufSerial;


}




My problem is these 2 lines, in both I need a pointer to a string and I'm having trouble doing it in vb6. Any suggestions or using my dll is the only solution.

GETDRIVERPAR(290,(LPVOID)bufSerial))
SETDRIVERPAR(290,(LPARAM)buffer))

#4
sallreen

sallreen

    Newbie

  • Members
  • Pip
  • 1 posts
A string is a data type consisting of a series of characters. While we treat it as a simple data parameter, it is in reality closely related to an array. In fact, some other languages (such as C++), force the developer to manipulate strings as if they were arrays. In VB, strings are treated as a variable, the same way an integer, for example, would be treated.
----------------------
Sally
drivenwide

#5
reniery

reniery

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Yeah but there is a difference in structure in how strings are handle in vb and in c++. For example C strings are arrays of characters terminated by a NULL character. Visual Basic strings differ in that the length of the string preceded the characters in the string. C++ BSTR is the same as the String in VB so im using that in my c++ dll.

But actually my problem is with using pointers in vb6, what I need to do is a pointer to a string but until now I have only been able to point to the first char of the string using strptr() . In c++ I did it using the code a previously posted but haven´t found a vb6 equivalent yet.

So is it posible :confused:

On a side note: VB I despise you:mad:

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Thank you for telling me that, which I could also have found in two seconds on Wikipedia. Reporting.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
reniery

reniery

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Found what exactly ? ......

#8
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
I believe it was a post which were deleted. Spam. A lot of it now recently.
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#9
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Yes, it was spam, now deleted because I reported him to Jordan.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#10
reniery

reniery

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
ok... cause I thought you were refering to something I posted....

#11
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
No no, don't worry.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums