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

Visual Basic

 
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 
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 
Very beautiful question.Thumbs Up | :thumbsup:

LPSAFEARRAY is a pointer itself, so LPSAFEARRAY* is a pointer to pointer declaration. This is what I would try:

VB
Public Declare Function EncenderLEDs Lib "MonAuto.dll" (cbLeds() As IntPtr, estado As Boolean) As Integer)


Your first array initialization is ok, but in order to pass it to that function, you should first pin the objects in the managed heap, create the IntPtr array with their addresses and pass this array. This is very similar to another question I answered in C# forum[^] some time ago, so let me bring it to you with some of the required changes. It is still C#. I will not convert it to VB becouse I do not feel comfortable enough with this language, and I could end up with a little mess.

C#
GCHandle[] handleArray = new GCHandle[cbLeds.Length];
for (int i=0; i<cbLeds.Length; i++)
    handleArray[i] = GCHandle.Alloc(cbLeds[i], GCHandleType.Pinned);

IntPtr[] pointers = (from GCHandle handle in handleArray select
                        handle.GetAddrOfPinnedObject()).ToArray();

int ret = EncenderLEDs(pointers, false)
// Release the handles
foreach (GCHandle handle in handleArray)
    handle.Free();


Please, let us know if it worked.
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 
QuestionRe: How to use google map in vb.net application Pin
ejaz_pk4-Mar-11 20:48
ejaz_pk4-Mar-11 20:48 

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.