Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB9.0 C++
Im trying to call a function from a c++ dll within a class from vb 2008, the library its compiled with .def file to be accessible from vb 2008 and I have been calling other functions from it (the CrearClase and the DestruirClase) without any error messages, the code in c++ is:
void * _stdcall CrearClase();
void _stdcall DestruirClase(void * objptr);
int _stdcall Funcion(void * objptr, const char* Param1, const char* Param2, const char* Param3, __int64 Param4, double* Param5);
<p>
void * _stdcall CrearClase()
    {
        return new Clase;
    }
<p>
void _stdcall DestruirClase(void * objptr)
    {
        Clase *d = (Clase *) objptr;
        if (d)
        delete d;
    }
<p>
int _stdcall Funcion(void * objptr, const char* Param1, const char* Param2, const char* Param3, __int64 Param4, double* Param5)
    {
        Clase *d = (Clase *) objptr;
        if (d)
            return d->FuncionClase(hands, board, dead, numberOfTrials, results);
        else
            return 0;
    }
</p></p></p>
and in the vb end looks like this:
 
Private Declare Function CrearClase Lib "Library.dll" () As Long
<p>
Private Declare Sub DestruirClase Lib "Library.dll"; (ByVal objptr As Long)
<p>
Private Declare Function Funcion Lib "Library.dll"(ByVal objptr As Long, ByRef Param1 As String, ByRef Param2 As String, ByRef Param3 As String, ByVal Param4 As Int64, ByRef Param5 As Double) As Integer
<p>
Dim buf As Integer
Dim objptr As Long
Dim Param1 As String
Dim Param2 As String
Dim Param3 As String
Dim Param5(0 To 1) As Double 'since it should return two values in here
<p>
Param1 = &quot;something&quot;
Param2= &quot;&quot;
Param3= &quot;&quot;
Param5(0)=0
Param5(1)=0
<p>
objptr = CrearClase()
buf = Funcion(objptr, Param1, Param2, Param3, 100000, Param5(0))
DestruirClase(objptr)
</p></p></p></p></p>
What seems to be the problem, what types of variables should i pass to the function in c++, im getting this error:
 
"Debug Assertion Failed!
 
Program: c:\bla\la\microsoft visual studio 9.0\vc\include\vector
Line: 779
 
Expression: vector subscipt out of range"
 

Thanks in advance
Posted 8-Dec-10 20:45pm
FERPROG381
Edited 12-Dec-10 3:45am
v4
Comments
prerakpatel at 9-Dec-10 7:57am
   
Need more details on error/problem.
Abdul Quader Mamun at 12-Dec-10 8:45am
   
spelling check.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Honnestly, if you don't explain what the problem is, we won't be able to answer... What is going wrong ? Do you have an error message ? If yes, paste it here with a description on when it occurs.
  Permalink  
Comments
Dalek Dave at 9-Dec-10 3:54am
   
You tell him Cedric!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try to put breakpoint in your cpp code at the begining of each function.
Also you may try to use type VARIANT instead of String.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Ok so i did it, maybe my question really wasnt correctly formulated, anyway tahnks to Kozlov and Cedric, the problem was creating the class and those string variables that are really different between languages, or at least thats how i get rid of it, heres how it all worked out:
 
C++:
int _stdcall Funcion(LPCSTR Param1, LPCSTR Param2, LPCSTR Param3, double * Param5);
br mode="hold" />int _stdcall Funcion(LPCSTR Param1, LPCSTR Param2, LPCSTR Param3, double * Param5)
	{
	    
		const char * Param11= (const char *) Param1;
		const char * Param21= (const char *) Param2;
		const char * Param31 = (const char *) Param3;
		int Param4 = 1000000;
		Clase Objeto;
		int Test = Objeto.FuncionClase(Param11, Param21, Param31, Param4, Param5);
		return Test; 
				
	}
 
I decide to leave Param4 as a constant within the wrapper function since it itsn to signifficative.
 
And in the VB end:
 
 [System.Runtime.InteropServices.DllImport>("Lib.dll")> _
    Private Shared Function Funcion(ByVal Param1 As String, ByVal Param2 As String, ByVal Param3 As String, ByRef Param5 As Double) As Integer
End Function
        Dim Param1 As String
        Dim Param2 As String
        Dim Param3 As String
        Dim Param5() As Double
        Dim Test as Double
        Param1="Something"
        Param2="Something Else"
        Param3="Something Even Else"
        Redim Param5(n) as Double 'n not a variable
        Param5(0)=0
        Test=Funcion(Param1, Param2, Param3, Param5(0))     
 
And that was it, again thanks a lot.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 12 Dec 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100