Solved

C++ DLL> Parameters from VB

Posted on 1998-12-31
9
181 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 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.
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.

821 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