Link to home
Start Free TrialLog in
Avatar of ianouii
ianouii

asked on

String Handling in VB .Net

I have a fine working code in VB6 which goes like this:


        Dim strPhoto As String
        strPhoto = Space(4000)
        nResult = Read_Photo(strPhoto)
       
which the strPhoto reads out an image file contents in binary format.
Note: Read_Photo is an API call.

as when I convert this to VB .Net, the strPhoto reading can't take in the correct binary format.
any idea? Pls advise.
Avatar of webtrans
webtrans

how to read binary file in .net is as below
http://www.dotnet4all.com/Dot-Net-Books/2004/08/read-binary-file.html
Avatar of ianouii

ASKER

I think u misunderstood. The API calls to return the binary string is a fixed function where I can't change that....

Rite now, I need the solution to manipulate the string in VB .Net just like how it react in VB6.

tqvm.
Hi ,
what kind of argument Read_Photo takes. just string ?
What Read_Photo(strPhoto) is giving you ?

-Baan
DId you change your API for using in .NET

Long will become Integer
Any will become Object
Avatar of ianouii

ASKER

Read_Photo(string) is a fixed API which is directly given by the hardware provider where we can't change anything to it. It's only expecting string input.

the string will be filled up with all the binary info once the Read_Photo function successfully executed.

tqvm.
So, when you do this...  nResult = Read_Photo(strPhoto)
What's it giving you ?
-Baan
Avatar of ianouii

ASKER

the nResult will just return successful code.

but the strPhoto will return big junk of binary info of a jpg format photos.

I'll then need to put that into a file by using the fileopen command in VB .net
let's concentrate in getting the string done to get the proper info.

tqvm.
So you are concerned about "strPhoto = Space(4000)" , right ?
-Baan
Do you think the problem is with the size ? try making the size bigger, lets see what happens.
Avatar of ianouii

ASKER

I've made the space(500000)
still, it doesn't work.
Avatar of Bob Learned
I think what Iouri was alluding to, what is your API defined as:

Bob
Long in VB.NET is a 64-bit number, while Integer is a 32-bit number.  In defining the API declaration, you need to keep that in mind.

Bob
Avatar of ianouii

ASKER

It has nothing with the nResult.
The API declared can't be changed as it's provided by the hardware manufacturer.
The driver provider is set to take string input only.
Okay, let's try it one more time.  Can you post your API declaration for us to see (both the VB6 and VB.NET declarations), please?

Thanks,
Bob
Avatar of ianouii

ASKER

VB6.
Declare Function Read_Photo Lib "gsdk.dll" Alias "_Read_Photo@4" (ByVal pbPhoto As String) As Integer

VB .Net
Declare Function Read_Photo Lib "gsdk.dll" Alias "_Read_Photo@4" (ByVal pbPhoto As String) As Integer
Yes, in this case there is nothing to change. But if it were declared as Long, you shoud've declared it as integer
Avatar of ianouii

ASKER

any resolution?
Actually, what kind of string does ReadPhoto take?
Avatar of ianouii

ASKER

just a normal string....
You might need to use the MarshalAsAttribute:

<MarshalAs(UnmanagedType.LPWStr)>

Declare Auto Function Read_Photo Lib "gsdk.dll" Alias "_Read_Photo@4" (ByVal pbPhoto As <MarshalAs(UnmanagedType.LPWStr)>String) As Integer

Bob
What kind of class it gsdk.dll?

Bob
Avatar of ianouii

ASKER

pls explain further over what're the info u wanna obtain?

the gsdk.dll exposed the API calls for Read_Photo...
Is gsdk.dll a C++ program, VB6 dll, ...?

Bob
Avatar of ianouii

ASKER

I think it's a C++ program.
not very sure about this.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial