interop between VB.NET and eVC++

E

Eric BOUXIROT

hi there,

i'm working on a smart application project on VB.NET. i must call API
(custom eVC++ DLL) but i have some trouble with mashalas attribute.....
i have copy/past a sample on msdn help but it's not working..
IDE says "unknown 'mashalAs' attribute".....and i don't know why....

i have try exactly the same code on a normal windows project and it work
(compile) fine...

i don't know what i've missed....

here some lines of my code...

thank a lot...

Imports System.Runtime.InteropServices

Public Class Form1

Public Declare Function F_BDO_MessageBoxOK Lib "PDA_BDO.dll" (ByRef
IN_title() As Byte, <MarshalAs(UnmanagedType.LPStr)> ByRef IN_msg As String)
As Int32
 
A

Alex Feinman [MVP]

MarshalAs attribute is not supported in CF - simply drop it, and your string
will be passed as LPCWSTR (note the constant part)
As for a byte array, replace ByRef with ByVal - the array will be passed
down as LPBYTE
 
E

Eric BOUXIROT

oh ok.....

thank, but i have one more question...
in my eVC++ DLL some functions use non-unicode strings (unsigned char*)

how i can tell VB to call DLL with non-UNICODE string format ?

thank a lot !
 
C

Chris Tacke, eMVP

Pass a byte array.

-Chris


Eric BOUXIROT said:
oh ok.....

thank, but i have one more question...
in my eVC++ DLL some functions use non-unicode strings (unsigned char*)

how i can tell VB to call DLL with non-UNICODE string format ?

thank a lot !
 
E

Eric BOUXIROT

yes i have already test this....it's ok but in my VB code i can't directly
convert String to byte array..

like this..
DLLFunction ("Toto".tobytearray)

i must declare one byte array then fill it with the string chars....then
call my function...
Dim bytearray(50) as byte
convertstring2bytearray ("toto",bytearray)
DLLFunction(bytearray)

i prefer the first method....but how i can implement the toByteArray method
to the string class ?

thank a lot .
 
C

Chris Tacke, eMVP

Use the Encoding class to change it.

-Chris


Eric BOUXIROT said:
yes i have already test this....it's ok but in my VB code i can't directly
convert String to byte array..

like this..
DLLFunction ("Toto".tobytearray)

i must declare one byte array then fill it with the string chars....then
call my function...
Dim bytearray(50) as byte
convertstring2bytearray ("toto",bytearray)
DLLFunction(bytearray)

i prefer the first method....but how i can implement the toByteArray method
to the string class ?

thank a lot .

"Chris Tacke, eMVP" <[email protected]> a écrit dans le message
de news: (e-mail address removed)...
 
A

Alex Feinman [MVP]

Dim chars as Byte() = System.Text.Encoding.ASCII.GetBytes(myString)
THis is what you need to pass down to the unmanaged code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top