Solved

C++ DLL> Parameters from VB

Posted on 1998-12-31
9
178 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

895 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

12 Experts available now in Live!

Get 1:1 Help Now