Simple C++ Dynamic Link Library

Simple C++ Dynamic Link Library

I am trying to interface VBA with a C++ DLL. I am very new to C++ programming. I understand the declarations from the VBA side, but I am having a tough time authoring a simple C++ DLL. Could you help me with a small example of a C++ DLL with only one simple function? I can successfully build a DLL with a simple function, but I keep getting an error in VBA telling me that the DLL entry point can’t be found.

The first concern is name mangling required by C++ in order to support things like function overloading. If you use a tool to list the exported functions from your DLL, you’ll probably find they are different from the ones you expect. You could simply use the mangled names as they are exported, but it’s probably better to find a way to export “C” functions to avoid the C++ name mangling. The exact way to do this depends on your code (whether it’s classes or what exactly–note that cannot call C++ class members directly from VB).

The second concern is that, contrary to what you’ll find in the Microsoft documentation, you need to create a .DEF with an EXPORTS section that lists your exported symbols. This is required because even straight C functions will mangle the names slightly, and the .DEF file entries allow you to control this.

See also  How to Avoid Money Transfer Scams  

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist