Passing an array of strings from VB to C 
Author Message
 Passing an array of strings from VB to C

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);

Quote:
}

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.



Wed, 11 Jul 2012 23:33:43 GMT  
 Passing an array of strings from VB to C

Quote:

> 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



Wed, 11 Jul 2012 23:54:30 GMT  
 Passing an array of strings from VB to C


Quote:
> 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



Thu, 12 Jul 2012 00:10:39 GMT  
 Passing an array of strings from VB to C

Quote:
> 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.


Thu, 12 Jul 2012 02:28:27 GMT  
 Passing an array of strings from VB to C

Quote:


>> 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



Thu, 12 Jul 2012 03:54:39 GMT  
 Passing an array of strings from VB to C

Quote:

>> 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.

I would agree with your thinking.  The level of expertise with more
esoteric stuff would be in this newsgroup.   So if you didn't get an
answer elsewhere in a VBA newsgroup then definitely ask here.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
  updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/



Thu, 12 Jul 2012 04:09:02 GMT  
 Passing an array of strings from VB to C

+1



Thu, 12 Jul 2012 05:17:28 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Passing String Arrays between VB and VC

2. passing (string) arrays from VB to C-DLL and vice versa

3. Passing an array of strings from VB to Windows API

4. Passing array of strings to a dll in VB

5. Passing an array of Strings to VB via ActiveX

6. Passing VB String array to DLL???

7. Passing String Arrays between VB and VC

8. passing (string) arrays from VB to C-DLL and vice versa

9. passing (string) arrays from VB to C-DLL and vice versa

10. How to pass a string Array from VB to a C++ DLL

11. String to Array and Array to String

12. Passing array from VB to DLL and returning array

 

 
Powered by phpBB® Forum Software