Click here to Skip to main content
15,909,325 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHow to have common Sub or Function? Pin
Paramu197310-Mar-11 0:28
Paramu197310-Mar-11 0:28 
AnswerRe: How to have common Sub or Function? Pin
Dalek Dave10-Mar-11 0:46
professionalDalek Dave10-Mar-11 0:46 
GeneralRe: How to have common Sub or Function? Pin
Paramu197310-Mar-11 1:02
Paramu197310-Mar-11 1:02 
GeneralRe: How to have common Sub or Function? Pin
Simon_Whale10-Mar-11 5:03
Simon_Whale10-Mar-11 5:03 
AnswerRe: How to have common Sub or Function? Pin
_Erik_10-Mar-11 2:38
_Erik_10-Mar-11 2:38 
AnswerRe: How to have common Sub or Function? Pin
RobCroll10-Mar-11 3:13
RobCroll10-Mar-11 3:13 
AnswerRe: How to have common Sub or Function? Pin
ghaberek18-Mar-11 7:14
ghaberek18-Mar-11 7:14 
QuestionCalling from VB.net to a Dll Win32 function that uses safearray pointer Pin
edmonson9-Mar-11 6:04
edmonson9-Mar-11 6:04 
Hi,

I'am updating and old VB6 project to VB.net 2008.

My old project uses a Win32 Dll and TLB file to shared types.
From VB6 a reference is created to TLB file and interop works fine.

From VB.net I can import TLB file successfully and types are accessibles, but not the functions.

Using 'Declare Function' sentences to import DLL methods, I can access to DLL functions.

My Win32 DLL has methods that uses LPSAFEARRAY pointer as input parameters.

This is the declaration of one of this functions on DLL:

extern NOMANGLE short CCONV EncenderLEDs(LPSAFEARRAY *CBLeds, bool Estado);

To reference this from VB.net I write

Public Declare Function EncenderLEDs Lib "MonAuto.dll" (<MarshalAs(UnmanagedType.SafeArray)> ByRef CBLeds() As CBTipo, ByVal Estado As Boolean) As Integer


CBTIPO is defined on DLL as:

typedef struct{
	short Carta;
	short Borna;
} CBTipo;

The type is correctly visible at VB.net after TLB is imported.

I test the function with next code:

Dim  CBLeds() as CBTipo
Redim CBLeds(4)
CBLeds(0).Borna = 0
CBLeds(0).Carta = 0
EncenderLEDs(CBLeds, False)


An exception is reported:

(Exception of HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))

But if I use any single Type to create the array: Int32, Double, Single, byte, ... and modify the declaration function definition on Vb.net like:

Public Declare Function EncenderLEDs Lib "MonAuto.dll" (<MarshalAs(UnmanagedType.SafeArray)> ByRef CBLeds() As Integer, ByVal Estado As Boolean) As Integer


and modify the test in the same way:

<pre>Dim CBLeds() as Integer
Redim CBLeds(4)
CBLeds(0).Borna = 0
CBLeds(0).Carta = 0
EncenderLEDs(CBLeds, False)</pre>

Then the call is processed good.

The question is, How must be defined a DLL Win32 function on VB.net that uses a LPSAFEARRAY * as input parameter, to send a userdefined type array ?

I've tried:
Public Declare Function EncenderLEDs Lib "MonAuto.dll" (<MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_USERDEFINED)> ByRef CBLeds() As CBTipo, ByVal Estado As Boolean) As Integer


and fails too.

Regards in advance
AnswerRe: Calling from VB.net to a Dll Win32 function that uses safearray pointer Pin
_Erik_10-Mar-11 3:00
_Erik_10-Mar-11 3:00 
GeneralRe: Calling from VB.net to a Dll Win32 function that uses safearray pointer Pin
edmonson10-Mar-11 4:55
edmonson10-Mar-11 4:55 
GeneralRe: Calling from VB.net to a Dll Win32 function that uses safearray pointer Pin
_Erik_10-Mar-11 5:41
_Erik_10-Mar-11 5:41 
GeneralRe: Calling from VB.net to a Dll Win32 function that uses safearray pointer Pin
edmonson10-Mar-11 5:45
edmonson10-Mar-11 5:45 
GeneralRe: Calling from VB.net to a Dll Win32 function that uses safearray pointer Pin
_Erik_10-Mar-11 5:58
_Erik_10-Mar-11 5:58 
GeneralRe: Calling from VB.net to a Dll Win32 function that uses safearray pointer Pin
edmonson10-Mar-11 6:31
edmonson10-Mar-11 6:31 
Questionvb.net with crystal reports deployment Pin
directred7-Mar-11 1:10
directred7-Mar-11 1:10 
QuestionHow to set focus on dynamically created controls? Pin
Floodlight6-Mar-11 16:40
Floodlight6-Mar-11 16:40 
AnswerRe: How to set focus on dynamically created controls? Pin
_Erik_7-Mar-11 4:59
_Erik_7-Mar-11 4:59 
GeneralRe: How to set focus on dynamically created controls? Pin
Floodlight7-Mar-11 22:58
Floodlight7-Mar-11 22:58 
QuestionAlpha Transparent PNG form question Pin
FeRtoll5-Mar-11 5:46
FeRtoll5-Mar-11 5:46 
QuestionWindows service with FileSystemWatcher Pin
byka4-Mar-11 5:22
byka4-Mar-11 5:22 
AnswerRe:[Cross Post] Pin
Henry Minute4-Mar-11 5:53
Henry Minute4-Mar-11 5:53 
AnswerRe: Windows service with FileSystemWatcher Pin
nlarson117-Mar-11 7:26
nlarson117-Mar-11 7:26 
QuestionHow to use google map in vb.net application Pin
ejaz_pk4-Mar-11 1:03
ejaz_pk4-Mar-11 1:03 
AnswerRe: How to use google map in vb.net application Pin
Simon_Whale4-Mar-11 3:27
Simon_Whale4-Mar-11 3:27 
AnswerRe: How to use google map in vb.net application Pin
Eddy Vluggen4-Mar-11 4:39
professionalEddy Vluggen4-Mar-11 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.