Solved

C++ DLL> Parameters from VB

Posted on 1998-12-31
9
177 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now