Solved

C++ DLL> Parameters from VB

Posted on 1998-12-31
9
180 Views
Last Modified: 2010-04-02
Hi,

I try to call a function in a DLL from VB, and I have few problems:

VB Declaration>
Public Declare Function GetDocumentPathname Lib "ps_API10.dll" (ByVal sString1 As String, ByRef sString2 As String) As Long
VB Code>
Response = GetDocumentPathname("Some text", sDocPathname)

C++>
long __stdcall CWordAPIApp::GetDocumentPathname(char sString1[100],char* sString2)
{
     strcpy(sString2, sString1);
     Return (0);
}

I'm expecting in my VB code to get: sDocPathName = "Some text", but it doesn't work.
I guess there is a problem with passing parameter by value or by reference, but I cannot find which (can I use 'strcpy' for this kind of job? ).

Any idea?

Thanx
0
Comment
Question by:SergeD
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1181335
Both parameters should be byval
0
 

Author Comment

by:SergeD
ID: 1181336
What do you mean, byval?

I'd like to pass one by value and one by reference. So I can assign one with the other.

Isn't it possible?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1181337
string by reference is char** in C++
string by value is char*

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:SergeD
ID: 1181338
So, the right C++ declaration should be:
long __stdcall CWordAPIApp::GetDocumentPathname(char* sString1,char** sString2)

but how to use strcpy?
 
strcpy(*sString2, sString1); ?
 
Ta,
0
 

Expert Comment

by:Mithander
ID: 1181339
I belive you want something like this.  Assuming the VB is right, the C++ should be.

long __stdcall CWordAPIApp::GetDocumentPathname(char* sString1,char** sString2)
{
char *temp=new char[strlen(sString1)+1];
strcpy(temp,sString1);
delete (*sString2);
(*sString2)=temp;
}

the only problem might be with the new and delete.  I was told you need to use them, but I'm not sure if this is the right way.  I don't think that you can just copy over the string, because you don't know the size of the block of memory it stores.
0
 

Author Comment

by:SergeD
ID: 1181340
So, the right C++ declaration should be:
long __stdcall CWordAPIApp::GetDocumentPathname(char* sString1,char** sString2)

but how to use strcpy?
 
strcpy(*sString2, sString1); ?
 
Ta,
0
 

Author Comment

by:SergeD
ID: 1181341
Hi Lads!

Thanx for your answers, much appreciated.

I give the points to Mithander, but another question is waiting for Mirkwood.

Bye.
Serge
0
 

Accepted Solution

by:
Mithander earned 20 total points
ID: 1181342
Thanks Serge
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1181343
SergeD, your function isn't working in VB because VB doesn't use zero (NULL) based strings,  declares the strings in its own way...

-Viktor
--Ivanov
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question