From: Francogrex on
Hi, I can pass single strings between VB and C (dll) without problem.
But now I am trying to pass an array of strings from VB to a C file
(as a test) but that is not working at all maybe someone can give
hints. I'm using VBA for excel. Thanks.

The C file that is made into 'mydll.dll"
#include "windows.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
__declspec (dllexport) void __stdcall CFUN(LPSTR **pout)
{
FILE *in=fopen("c:/excel.txt","w");
int i;
for (i=0;i<4;i++)
{
fprintf(in, "%s\n", *(pout+i));
}
fclose(in);
}

The VBA code:
Private Declare Function CFUN& Lib "c:/mydll.dll" (ByRef pout As
String)
Sub TEST()
Dim pout(4) As String
pout(0) = "one"
pout(1) = "two"
pout(2) = "three"
pout(3) = "four"
CFUN (pout(0))
End Sub

The excel.txt file does not contains the strings.
From: Ralph on
Francogrex wrote:
> Hi, I can pass single strings between VB and C (dll) without problem.
> But now I am trying to pass an array of strings from VB to a C file
> (as a test) but that is not working at all maybe someone can give
> hints. I'm using VBA for excel. Thanks.
>

"How To Pass Arrays Between Visual Basic and C"
http://support.microsoft.com/kb/207931

An 'Array' is an object in VB. In C it is a block of memory using an
addressing convention. You can manage VB Arrays in C using a SAFEARRAY, but
VB also provides methods to manage the "array buffer" as a contiguous block.

-ralph


From: MikeD on


"Francogrex" <franco(a)grex.org> wrote in message
news:8b12cee0-2a0e-4c6f-b452-17cb35b0b738(a)a32g2000yqm.googlegroups.com...
> Hi, I can pass single strings between VB and C (dll) without problem.
> But now I am trying to pass an array of strings from VB to a C file
> (as a test) but that is not working at all maybe someone can give
> hints. I'm using VBA for excel. Thanks.

You can try what's in these KB articles, but note that they are for VB, not
VBA. There could be differences, or the information could be completely
inapplicable to VBA. That's why there are separate newsgroups for VBA.

How to pass arrays and strings between Visual Basic and C functions or
between Visual Basic and C++ functions by using Visual Basic 6.0
http://support.microsoft.com/kb/205277

How To Pass a String Between Visual Basic and Your C DLL
http://support.microsoft.com/kb/187912

How To Pass Array of UDTs with Variable Length Strings to C/C++
http://support.microsoft.com/kb/194609

If these don't help, I suggest you ask in a VBA newsgroup.

--
Mike


From: Francogrex on
On Jan 23, 5:10 pm, "MikeD" <nob...(a)nowhere.edu> wrote:
> If these don't help, I suggest you ask in a VBA newsgroup.

Ok I did, I'm sorry, I had asked many times VBA questions in excel/
programming forums but I rarely get replies and I don't think the
level of expertise in programming in those forums is as high as here.

From: Ralph on
Francogrex wrote:
> On Jan 23, 5:10 pm, "MikeD" <nob...(a)nowhere.edu> wrote:
>> If these don't help, I suggest you ask in a VBA newsgroup.
>
> Ok I did, I'm sorry, I had asked many times VBA questions in excel/
> programming forums but I rarely get replies and I don't think the
> level of expertise in programming in those forums is as high as here.

The 'coding' aspects in *this* case are identical.

Starting with VBA 5.x and VB 5 the 'core' language of both platforms is
identical. The difference between the two is primarily the language
'extension libraries' availble to a specific host environment and the fact
VBA applications/macros etc. can only be run within a host.

Becoming an advanced programmer in VBA entails learning the difference as
well as learning the nuances of the extension libraries for a specific
product. An excellent reference book on the core language of both VBA and VB
is O'Reilly's "VB & VBA In A Nutshell" by Paul Lomax. It is out of print,
but used books can be purchased on the web for practically the cost of
shipping.

-ralph


 |  Next  |  Last
Pages: 1 2
Prev: InStr issue
Next: Simple question