473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cpp function to return a string

Hope there are some mixed language programmers here. Trying to write a c++
dll for my VB6 program. To help me with my understanding, I just want to
pass it
a VB long (c++ int) & have it return that number of characters as a string,
any character. I know about the def file, using stdcall etc. I envision it
as
something like

LPCSTR _stdcall ReturnAString(int NumChars)
but not sure about LPCSTR

and the VB Declare would be something like

Private Declare Function ReturnAString Lib "MyDLL" (ByVal NumChars As Long)
As String

In VB,
Dim A As String
A = ReturnAString(10) & get A = "AAAAAAAAAA"

I suspect the c++ function has to allocate the string with one of
the SysAlloc family of calls. Any ideas?
Jul 23 '05 #1
3 2811
Norm Cook wrote:
Hope there are some mixed language programmers here. Trying to write a c++
dll for my VB6 program. [...]

I suspect the c++ function has to allocate the string with one of
the SysAlloc family of calls. Any ideas?


You need to ask either in a Visual C++ newsgroup or in a Visual Basic
newsgroup or a Windows programming newsgroup. _Standard_ C++ language
(the sole subject of _this_ newsgroup) does not have any specific means
for mixed language programming except with C. All others are compiler-
specific.

V
Jul 23 '05 #2
Norm Cook wrote:
Hope there are some mixed language programmers here.
I am a very mixed programmer.
Trying to write a c++
dll for my VB6 program.
Start again, and this time create a New ATL ActiveX DLL project.

Use the class wizard to create a class in this project. Give it a method
Foo, with these arguments:

[out, retval] BSTR *

Inside that method, use (IIRC) SysAllocString to turn a local string into a
BSTR.

The deal is strings are arrays in memory, so they can't copy around easily.
But different programs in a protected mode architecture have different
memory locations. So the OS supports a "string handle" type, which is BSTR.
LPCSTR _stdcall ReturnAString(int NumChars)
but not sure about LPCSTR
Private Declare Function ReturnAString Lib "MyDLL" (ByVal NumChars As Long) As String


That won't work because the VB String object _is_ a BSTR. A Basic STRing.
You might eventually figure out how to coerce your string pointer into a
BSTR (and your string is in-process, so it's in the same address space). But
you might as well learn to do things the correct way. Only legacy DLLs
should use the Declare Function system. Any new code should start with
ActiveX.

All of this topic is best served by Microsoft's newsgroups. This newsgroup
is only qualified to discuss raw C++ itself.

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand

Jul 23 '05 #3
Phlip wrote:
[OT response to an OT question removed]
Please, kindly supply at least some indication that you're posting
off-topic. I would really like avoid downloading those. "[OT]" in the
subject would do nicely. Thanks.
All of this topic is best served by Microsoft's newsgroups. This newsgroup
is only qualified to discuss raw C++ itself.

V
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
8
by: Johno | last post by:
I have written the two associated base classes below (Digital_camera and Review) to manage digital camera and review objects. They are base classes for which other derived classes can be written to...
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
2
by: pangel83 | last post by:
I've been trying for days to write a piece of VB.NET code that will read from winamp's memory space the paths of the files from the current winamp playlist. The GETPLAYLISTFILE command of the...
4
by: Paul | last post by:
Anyone have code that emulates the Nz function in Microsoft Access? In Access it is: Nz(Value as variant, Optional ValueIfNull as Variant) as Variant
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
4
by: default | last post by:
Hello All. I was looking around for a function like strtok() which would tokenize on the complete list of delimiters, rather than tokenize on *any* of the delimiters in the group. I ended up...
27
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1...
20
by: Andrew Morton | last post by:
Is it possible to have two function declarations which take the same parameters but return different types depending on how the function is used? function f(x) as string ' return a string end...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.