cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ametisse
Level 5

strings in c++ dll (unicode dll with visual c++)

Hello every body,

(Sorry for my bad english... :rolleyes: )

I'm trying to use a funtion which is in my c++ dll.
If my function is something like that :
int nameFunc (int myValue)
{
return myValue;
}

Everything is ok.
So the link between my dll and my InstallShield project is ok.

But if my function use "string" instead of int :
string nameFunc (string myValue)
{
return myValue;
}

There is a problem :
the dll being called encountered a problem


I use this dll in a custom action created with the wizard :
-> name

-> call a function in a standard dll

-> stored in a binary table

-> function def :

* name = nameFunc
* argument :
Type = STRING ;
Source = InProperty ;
Value = COMPANYNAME

* return type = STRING
* returnproperty = RESULT


I have done very much searches about this problem. I have understood that my dll must be done in unicode to accept strings. But I don't know how I can do that with visual C++ (I have done this dll myself and I can change it if it's necessary)

Is there someone who can help me to do a good dll with VisualStudio c++ in order to use it (with strings) in InstallShield ?

Thank you.
Labels (1)
0 Kudos
(24) Replies
ametisse
Level 5

😞
nobody can help me ...
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

First off, if the string you refer to in your c++ code is std::string, you'll have all sorts of problems with this approach; it's best to use least common denominator types when interfacing between different languages. In this case, you should use something like LPCSTR (aka char const*) for your input parameter; I'm not sure how to suggest returning the string, except to use it as an in/out parameter (LPSTR aka char*).
0 Kudos
ametisse
Level 5

Hello MichaelU, and hello everybody

Thank you very much for your help MichaelU. My dll works now, every things are OK.

If somebody wants to know the code which is OK :

Here, my function in my c++ program :
typedef char* LPSTR;

LPSTR get_Action(LPSTR resultat)
{
return resultat;
}


And here, the Function signature in my installshield custom action :
[HTML]STRING=[RESULT]ScriptInstall::get_Action(in STRING=[COMPANYNAME])[/HTML]


Thank you very much !
0 Kudos
ametisse
Level 5

Hello every body

My dll is not so OK that I thought. 😞

If I use this code :
typedef char* LPSTR;

LPSTR get_Action(LPSTR resultat)
{
return resultat;
}

I have a property "RESULT" which have a value before the dll function
And my dll function returns this value.
Every thing is OK.

But If I try to change this value in my dll function, there is a probleme :
typedef char* LPSTR;
LPSTR get_Action(LPSTR resultat)
{
resultat="test";
return resultat;
}


I have try with different types of strings :
LPSTR, LPWSTR, LPCWSTR ...

There isn't a good solution.


So, I try something else (function returns void):
typedef char* LPSTR;
void get_Action(LPSTR resultat)
{
resultat="test";
}


And in InstallShield , I have tried :
[CODE]STRING=void ScriptInstall::get_Action(out STRING=[RESULT])[/CODE]
[CODE]STRING=void ScriptInstall::get_Action(inout STRING=[RESULT])[/CODE]

But there is not a good result.

Is there someone who can help me ?
Is there an example of C++ dll which works correctly with InstallShield and which modify a string property ?

Have a nice day.
0 Kudos
ametisse
Level 5

nobody can help me ...
😞
0 Kudos
ametisse
Level 5

I have not found solution yet. 😞
If someone have an idea...
0 Kudos
MrTree
Level 6

ametisse wrote:
I have not found solution yet. 😞
If someone have an idea...


Maybe I can help you:
DLL

extern "C" CString WINAPI CheckDll(LPCTSTR lpszTest)
{
CString test;
test.Format("%s TEST", lpszTest);
return test;
}


IS function:

prototype STRING IsHelp.CheckDll(LPSTR);
export prototype STRING DllTest(LPSTR);

function STRING DllTest(sTemp)
int nResult;
STRING ret;
STRING test;
begin
nResult = UseDLL("C:\\Temp\\IsHelp.dll");

if(nResult != 0) then
MessageBox("Unable to load IsHelp.dll.", SEVERE);
exit;
endif;

ret = CheckDll(sTemp);
UnUseDLL("C:\\Temp\\IsHelp.dll");

return ret;
end;


IS function call:
sTeststring = DllTest(&sTeststring);
0 Kudos
ametisse
Level 5

Hello,

Thank you for your help MrTree. But I did not manage to make a correct code.

How the "IS function" must be done ? (custom action > VBScript code ?)

I have try like that :

Dll code :
#include "atlstr.h"
#include "cstringt.h"

extern "C" CString WINAPI CheckDll(LPCTSTR lpszTest)
{
CString test;
test.Format(L"%s TEST", lpszTest);
return test;
}


with the def file :
LIBRARY	"ScripInstall"

EXPORTS
CheckDll @1


IS function in a custom action (VBScript code) :
prototype STRING ScripInstall.CheckDll(LPSTR);
export prototype STRING DllTest(LPSTR);

function STRING DllTest(sTemp)
int nResult;
STRING ret;
STRING test;
begin
nResult = UseDLL("Z:\\FichiersInstallCeraSlice\\ScriptDLL\\ScripInstall.dll");

if(nResult != 0) then
MessageBox("Unable to load ScripInstall.dll.", SEVERE);
exit;
endif;

ret = CheckDll(sTemp);
UnUseDLL("Z:\\FichiersInstallCeraSlice\\ScriptDLL\\ScripInstall.dll");

return ret;
end;

session.property("RESULTAT") = DllTest(&(session.property("RESULTAT")));

(I have tried with and without the last row, but there is the same problem in these two cases.)

And I call the custom action on the "next" button of the dialog box "Customer informations".

Before I try this idea, when I launched the install, I had an error message. Now the install is stopped without message error. So I think there is a problem in InstallShield (not in the dll, or both).

I have never use scripts in InstallShield . Can you help me ?

Thank you every body.
0 Kudos
MrTree
Level 6

I think that should work:

DLL cpp

#include "stdafx.h"
#include "atlbase.h"

extern "C" LPCTSTR WINAPI CheckDll(LPCTSTR lpszTest)
{
CString test;
test.Format("%s TEST", lpszTest);
return test;
}


DLL def

LIBRARY IsHelp

EXPORTS
CheckDll


IS call

function OnFirstUIBefore()
STRING sFilename;
POINTER pFilename;
begin
sFilename = "something";
pFilename = &sFilename;
sFilename = DllTest(pFilename);
MessageBox(sFilename, INFORMATION);
exit;


IS function

prototype STRING IsHelp.CheckDll(LPSTR);
export prototype STRING DllTest(LPSTR);

function STRING DllTest(sTemp)
int nResult;
STRING ret;
STRING test;
begin
nResult = UseDLL("C:\\Temp\\IsHelp.dll");

if(nResult != 0) then
MessageBox("Unable to load IsHelp.dll.", SEVERE);
exit;
endif;

ret = CheckDll(sTemp);
UnUseDLL("C:\\Temp\\IsHelp.dll");

return ret;
end;
0 Kudos
ametisse
Level 5

Hi, thank you for your help MrTree.

But I don't manage to do something right.

Have you test your solution ?
If yes, what soft have you used to do the dll?

Thank you very much.
0 Kudos
MrTree
Level 6

Hi,

I tested the dll and it works, I build it with Visual Studio 2008. I attached the Source for you :cool:
0 Kudos
ametisse
Level 5

Hi MrTree, (and Hi every body too)

Thank you very much MrTree because now, I know that the dll I use is ok and I can search what is the problem in IS (because it doesn't work for me)

I think I have not understand something about the way to write the IS function, and to call it in IS.

For me there are differents ways to do that :
1- Doing a custom action with the custom action wizard

2- Use install script

(I have not tried with installscript, because I don't know how to do.)

What solution do you use to have something which works correctly ?

Thank you very much MrTree. 😮
0 Kudos
ametisse
Level 5

I think these informations are important :
I'm using InstallShield 2010 Professional Edition
And my project is a basic MSI project
0 Kudos
MrTree
Level 6

Thats it.

I use InstallShield 2010 SP1 Installscript Project.

I recommend using at least Installscript MSI (attached a sample proj) but I'm not very familiar with msi at all.
0 Kudos
ametisse
Level 5

Hi,

I think I can't change the type of my project (this one already existe)
There are very much things that are already done, so it's not possible to change it 😞
0 Kudos
MrTree
Level 6

0 Kudos
ametisse
Level 5

Hi MrTree.

Thank you for this link. I haven't seen it.

I think it's a new idea to use. But I don't know how to do.

I'm searching. 😞

Thank you
0 Kudos
ametisse
Level 5

Hi everybody,

My problem is not resolved yet.

My problem isn't to manage to use my dll in my basic MSI IS project, but only to use strings in this dll.

So I have try every possibilities you say me but the problem is always the same. I manage to use a function like that in my dll :
int myFunc (int value)
{
return (value+2);
}

Or a function like that (with no modification of the string value in the function :
typedef char* LPSTR;
LPSTR test(LPSTR val)
{
return val;
}


But if I try to use this function, (with the same way) :
typedef char* LPSTR;
LPSTR test(LPSTR val)
{
LPSTR res ="";
return res;
}

It does'nt work.

Is somebody who knows how to use a function (in a dll) which use strings ?

Thank you very much.
0 Kudos
ametisse
Level 5

Here,

If you want to try, I attach my Project IS, my DLL (and my project Visual Studio)
😞
0 Kudos
MrTree
Level 6

you only attached the projectfiles in your zip, there is no code -> helps not.

If your DLL looks like this:
#include "stdafx.h"
#include "atlbase.h"

extern "C" LPCTSTR WINAPI CheckDll(LPCTSTR lpszTest)
{
CString test;
test = "This is the test of";
test.Format("%s %s", test, lpszTest);

return test;
}


and you call it correct from IS it will work.
0 Kudos