PC Review


Reply
Thread Tools Rate Thread

C-DLL-VBA to excel (strings)

 
 
Francogrex
Guest
Posts: n/a
 
      24th Jun 2009
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 (Note that the dll I am making I tested and it works
well elsewhere because when I link it to an exe it is actually
returing a string as expected). 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C-DLL-VBA-EXCEL strings Francogrex Microsoft Excel Discussion 0 24th Jun 2009 04:42 PM
Is it simply that c# converts all strings coming in to double and strings going out to single? AAaron123 Microsoft C# .NET 3 23rd Feb 2009 01:08 PM
excel macro with strings Tomek Microsoft Excel Programming 2 3rd Mar 2005 05:31 PM
Make Word displays strings of text, not strings of code =?Utf-8?B?WGVybw==?= Microsoft Word Document Management 2 9th Dec 2004 10:35 AM
Excel Macro Strings Brandon Microsoft Excel Programming 16 14th Jul 2003 04:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:31 AM.