interop between VB.NET and eVC++
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

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

Reply to this message...
 
    
Alex Feinman [MVP] (VIP)
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

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Eric BOUXIROT" <Click here to reveal e-mail address> wrote in message
news:4145bf49$0$1291$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
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 !

"Alex Feinman [MVP]" <Click here to reveal e-mail address> a écrit dans le message
de news: Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Chris Tacke, eMVP (VIP)
Pass a byte array.

-Chris

"Eric BOUXIROT" <Click here to reveal e-mail address> wrote in message
news:4145c675$0$1302$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
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 .

"Chris Tacke, eMVP" <Click here to reveal e-mail address> a écrit dans le message
de news: Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Chris Tacke, eMVP (VIP)
Use the Encoding class to change it.

-Chris

"Eric BOUXIROT" <Click here to reveal e-mail address> wrote in message
news:4145ccab$0$1285$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Eric BOUXIROT
an small example ?

thank a lot !

"Chris Tacke, eMVP" <Click here to reveal e-mail address> a écrit dans le message
de news: Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Alex Feinman [MVP] (VIP)
Dim chars as Byte() = System.Text.Encoding.ASCII.GetBytes(myString)
THis is what you need to pass down to the unmanaged code

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Eric BOUXIROT" <Click here to reveal e-mail address> wrote in message
news:4145cef0$0$1300$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Eric BOUXIROT
ok thank a lot for your very quick answers...
it work fine....

"Alex Feinman [MVP]" <Click here to reveal e-mail address> a écrit dans le message
de news: Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Chris Tacke, eMVP (VIP)
Take a look at the sample in MSDN:

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemTextEncodingClassConvertTopic.asp

-Chris

"Eric BOUXIROT" <Click here to reveal e-mail address> wrote in message
news:4145cef0$0$1300$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Peter Foot [MVP] (VIP)
asciibytes = System.Text.Encoding.ASCII.GetBytes("Hello World")

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups

"Eric BOUXIROT" <Click here to reveal e-mail address> wrote in message
news:4145cef0$0$1300$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Runtime.InteropServices.UnmanagedType
System.Text.Encoding




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com