tmark01
asked on
VS 2008 - problem calling a C++ dll from VB.Net
We are trying to call C++ dll from a VB.Net application. Both projects are in VS 2008. We can succesfully call the dll from a C/C++ program, but not the VB.Net.
The message is:
"System error=Unable to find an entry point named 'fnRSIPackingLib' in DLL 'RSIPackingLib.dll'
Both projects are simple. Any help would be appreciated. Below is the source for both programs.
/************************* ********** ********** ********** *********/
// RSIPackingLib.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "RSIPackingLib.h"
// This is an example of an exported variable
RSIPACKINGLIB_API int nRSIPackingLib=0;
// This is an example of an exported function.
RSIPACKINGLIB_API int fnRSIPackingLib(int *tVal)
{
*tVal = 299;
return 42;
}
// This is the constructor of a class that has been exported.
// see RSIPackingLib.h for the class definition
CRSIPackingLib::CRSIPackin gLib()
{
return;
}
/************************* ********** ********** ********** *********/
RSIPackingLib.h
#ifdef RSIPACKINGLIB_EXPORTS
#define RSIPACKINGLIB_API __declspec(dllexport)
#else
#define RSIPACKINGLIB_API __declspec(dllimport)
#endif
// This class is exported from the RSIPackingLib.dll
class RSIPACKINGLIB_API CRSIPackingLib {
public:
CRSIPackingLib(void);
// TODO: add your methods here.
};
extern RSIPACKINGLIB_API int nRSIPackingLib;
RSIPACKINGLIB_API int fnRSIPackingLib(int *tVal);
/************************* ********** ********** ********** ********/
RSIPackingLib.def
LIBRARY RSIBackingLib
DESCRIPTION 'A C++ dll that can be called from VB'
EXPORTS
fnRSIPackingLib
/************************* ********** ********** ********** *********/
VB.Net code
Imports System.Runtime.InteropServ ices
Public Class Form1
<DllImport("RSIPackingLib. dll", CallingConvention:=Calling Convention .Cdecl)> _
Private Shared Sub fnRSIPackingLib(ByRef stan As Integer)
End Sub
Private Sub DisplayErrMsg(ByVal msg As String)
Call MsgBox("System error=" & msg, MsgBoxStyle.Critical, "Simple Test")
End Sub
Private Sub BtnSimple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSimple.Click
Dim Num As Integer = 8
Try
fnRSIPackingLib(Num)
MessageBox.Show("Num:" & Num)
Catch ex As Exception
Call DisplayErrMsg(Err.Descript ion)
End Try
End Sub
End Class
The message is:
"System error=Unable to find an entry point named 'fnRSIPackingLib' in DLL 'RSIPackingLib.dll'
Both projects are simple. Any help would be appreciated. Below is the source for both programs.
/*************************
// RSIPackingLib.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "RSIPackingLib.h"
// This is an example of an exported variable
RSIPACKINGLIB_API int nRSIPackingLib=0;
// This is an example of an exported function.
RSIPACKINGLIB_API int fnRSIPackingLib(int *tVal)
{
*tVal = 299;
return 42;
}
// This is the constructor of a class that has been exported.
// see RSIPackingLib.h for the class definition
CRSIPackingLib::CRSIPackin
{
return;
}
/*************************
RSIPackingLib.h
#ifdef RSIPACKINGLIB_EXPORTS
#define RSIPACKINGLIB_API __declspec(dllexport)
#else
#define RSIPACKINGLIB_API __declspec(dllimport)
#endif
// This class is exported from the RSIPackingLib.dll
class RSIPACKINGLIB_API CRSIPackingLib {
public:
CRSIPackingLib(void);
// TODO: add your methods here.
};
extern RSIPACKINGLIB_API int nRSIPackingLib;
RSIPACKINGLIB_API int fnRSIPackingLib(int *tVal);
/*************************
RSIPackingLib.def
LIBRARY RSIBackingLib
DESCRIPTION 'A C++ dll that can be called from VB'
EXPORTS
fnRSIPackingLib
/*************************
VB.Net code
Imports System.Runtime.InteropServ
Public Class Form1
<DllImport("RSIPackingLib.
Private Shared Sub fnRSIPackingLib(ByRef stan As Integer)
End Sub
Private Sub DisplayErrMsg(ByVal msg As String)
Call MsgBox("System error=" & msg, MsgBoxStyle.Critical, "Simple Test")
End Sub
Private Sub BtnSimple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSimple.Click
Dim Num As Integer = 8
Try
fnRSIPackingLib(Num)
MessageBox.Show("Num:" & Num)
Catch ex As Exception
Call DisplayErrMsg(Err.Descript
End Try
End Sub
End Class
ASKER
Thank you. I will try this. I am out of the office today, but will try it first thing tomorrow AM (8/17/12).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The exertn C did solve the problem. Thanks much for your help
the easiest way to verify it is to open your dll in Dependency Walker and see what it says about exported functions.