Solved

C++ DLL> Parameters from VB

Posted on 1998-12-31
9
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

718 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