Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a c++ dll and a corresponding VB console application. I am very C++ savvy but new to VB so I went through a couple tutorials. Here is the code for my tutorial DLL:

C++
#include "stdafx.h"
extern "C"
{
int _stdcall GetIntValue()
{
    return 8;
}
int _stdcall GetSum(int A, int B)
{
    return (A + B);
}
}



I also have a .def file with the two functions declared in it. Since I have a .def file I removed the __declspec(dllexport) from the code and added extern "C". My exported functions are not decorated in the .lib file.

My VB Application looks like this:

VB
Module Module1
    Private Declare Function GetIntValue Lib _
        "..\..\..\Release\Test_SimpleDLL.dll" () As Long
    Private Declare Function GetSum Lib _
        "..\..\..\Release\Test_SimpleDLL.dll" _
            (ByVal inA As Long, _
            ByVal inB As Long) As Long
    Sub Main()
        Console.WriteLine(GetIntValue())
        Console.WriteLine(GetSum(5, 12))
    End Sub
End Module


When I run it I get weird results. Sometimes I get the value '8' like I am supposed to for the first call, but most of the time it is some weird big number and it is not always the same weird number.

The second call almost always returns the value '5', but sometimes it also returns differing weird long numbers.

I have tried everything I can think of. Any ideas? Thanks.

Caleb
Posted
Updated 22-Apr-10 6:42am
v3

1 solution

As I understand you need to use DEF file to prevent mangling of names. In that case you should not use __declspec(dllexport).

Read this[^] article for more details.

-Saurabh
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900