C-DLL-VBA-EXCEL strings

F

Francogrex

Hello, I'm trying to connect excel to a C dll library (call C dll from
excel through the VBA). It works well for returning integer and double
values (see simple example below), but I can't seem to get it to
return strings. I am using MinGW gcc (so basically only C) to
construct my dll, so I don't have access to BSTR and other cpp like
objects/functions... Is there a way to make the C dll return strings
to excel? Thanks

DLL.c
#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
EXPORT int __stdcall add2(int num){
return num + 2;
}

COMPILE mydll.dll
c:\> gcc -c -DBUILD_DLL dll.c
c:\> gcc -shared -o mydll.dll dll.o -Wl,--add-stdcall-alias

IN VBA:
Private Declare Function add2 Lib "c:/mydll" _
(ByVal num As Long) As Long
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top