Re: SafeArrayTypeMismatchException - .NET GURUS PLEASE HELP

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Jun 5, 10:04 am, Phoenix <sudhansutiw...@xxxxxxxxx> wrote:
Hi .NET Masters :-)

Please help me to get out of following situation ...

There is a function in one of my dlls whose signature is as follows :
my_function(integer X, integer Y, char* Z, HAD A, HAD P)

Here HAD is defined as follows in one of the header files as :

#define HAD LPSAFEARRAY FAR *

The above dll was written in VC++ 6.0 . I use to call this function
in my Visual Basic 6.0 application.

Recently , I upgraded my Visual Basic application and found
that its giving "SafeArrayTypeMismatchException"

Declaration for my Function is as follows :

Declare Function my_function Lib "tcvbadm.dll" (ByVal X As Integer,
ByVal Y
As Integer, ByVal Z As String, A() As String, A() As Integer) As
Integer

And the way I am calling in my VB application is as follows :

Dim li_count as Integer
ReDim la_leaf(li_count) As String
ReDim la_access(li_count) As Integer

retcode = my_function(X, Y, Z, A(), B()) ' HERE I AM GHETTING THE
EXCEPTION
WHERE AS IT WAS WORKING WELL PREVIOUSLY

'I fetch li_count through a different fi=unction call which returns an
integer value.

Please let me know if any further info is reqd regarding this. Any
help
would be highly apprecaited ,
Thanks a lot in advance.

Thanks & Regards

Sudhansu Tiwari

I don't know what the problem is, but one thing you need to keep in
mind is that integers in .Net are 4 bytes. If the original function
signature (from the VC++ 6 dll) was asking for integers, in .Net that
translates to the short data type so you need to change your declare
statement accordingly.

Chris

.



Relevant Pages

  • Re: C-DLL and VB string conversion
    ... I have a C dll that I call from a vb6 program. ... Declare Function s_TranslateErrorValue Lib "SUB.DLL" (ByVal pSUB As ... Dim sError As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Passing arguments from VBA to DLL
    ... only the first character of String t seems ... Public Declare Function lstrlenW Lib "kernel32" ... "Although VBA uses Unicode internally, ... to ANSI strings before calling a function in a DLL". ...
    (microsoft.public.excel.programming)
  • Re: Anyone know the source of this code?
    ... Calling Visual C++ DLL Functions ... The problem is with your declare. ... you can't return that as a string in VB. ... Dim bStr() As Byte ...
    (microsoft.public.vb.general.discussion)
  • Re: How do I return a string from a C++ DLL to VB6?
    ... Private Declare Sub DllGetVersion Lib "mytest.dll" (ByVal szReturnVersion ... Dim sDLLVersion As String ... Works perfectly from the exe but not from the IDE. ... IDE-friendly way to pass strings from a C++ DLL to the host VB6 program? ...
    (microsoft.public.vb.general.discussion)
  • Re: Passing arguments from VBA to DLL
    ... only the first character of String t seems ... Public Declare Function lstrlenW Lib "kernel32" ... "Although VBA uses Unicode internally, ... to ANSI strings before calling a function in a DLL". ...
    (microsoft.public.excel.programming)