Re: passing a string to a dll



Just a guess, but did you include the header file for the DLL.

Also, you may want to define your functions for:

CString GetString();
CString LoadStringID(UINT stringID);

As

LPCTSTR GetString();
LPCTSTR LoadStringID(UINT stringID);

You can still assign to a CString on output:

CString cs = GetString();

Tom

"SteveR" <srussell@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:Ohn3ONj%23HHA.4460@xxxxxxxxxxxxxxxxxxxxxxx
Thank you all for your help.

I have now specified unicode in the dll, so it should match up with the application.
I have, for now at least, chosen to use CString& in both the dll and the application.

Please remember that I am not nearly as trained in depth as you all are, and therefore cannot make complete sense of what I am now presented with:

Room 101View.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall DLLRect::PullWhisker(class CString &)" (__imp_?PullWhisker@DLLRect@@QAE_NAAVCString@@@Z)

My dll:

// DLLRect.h: interface for the DLLRect class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DLLRECT_H__935F1132_14D8_4CC5_A466_5B6E1904C9B4__INCLUDED_)
#define AFX_DLLRECT_H__935F1132_14D8_4CC5_A466_5B6E1904C9B4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class AFX_EXT_CLASS DLLRect
{
public:
DLLRect();
virtual ~DLLRect();
CString GetString();
CString LoadStringID(UINT stringID);
bool PullWhisker(CString& s); //LPCTSTR s);

};

#endif // !defined(AFX_DLLRECT_H__935F1132_14D8_4CC5_A466_5B6E1904C9B4__INCLUDED_)
. . .
bool DLLRect::PullWhisker(CString& s)
{
if(s != _T("12345") )
::Beep(1000,200);
return true;
}

my app:

// DLLRect.h: interface for the DLLRect class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DLLRECT_H__935F1132_14D8_4CC5_A466_5B6E1904C9B4__INCLUDED_)
#define AFX_DLLRECT_H__935F1132_14D8_4CC5_A466_5B6E1904C9B4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class AFX_EXT_CLASS DLLRect
{
public:
DLLRect();
virtual ~DLLRect();
CString GetString();
CString LoadStringID(UINT stringID);
bool PullWhisker(CString& s); //LPCTSTR s);

};

#endif // !defined(AFX_DLLRECT_H__935F1132_14D8_4CC5_A466_5B6E1904C9B4__INCLUDED_)
. . .
in my view:

DLLRect r;
CString s = _T("12345");
r.PullWhisker(s);

----------
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message news:rdmve3hfmfb2hg5046kh4vb9rcdfu4e3ma@xxxxxxxxxx
First, DID YOU USE THE DEBUGGER TO EXAMINE THE STRING CONTENTS???? If not, why not? I do
things like this all the time without problems, so there is something about your
environment that you are not telling us, but more critically, you have not actually
examined the behavior of the code.

Are you doing static linking of the MFC library? In that case, all bets are off. You
can't pass MFC objects across library boundaries. In this case, you would have to use
LPCTSTR.

Is the example you are using EXACTLY using the string "12345" or is it using something
else?

Given the example below, you should be comparing the binary value of the string (12345) to
the numeric value 12345, which is why I suspect that the example you have shown here may
not be the example you are actually using.

Note that you would nominally be better of passing const CString & s instead of CString s
in such a case; it would be more efficient.
joe
On Mon, 17 Sep 2007 21:34:09 -0400, "SteveR" <srussell@xxxxxxxxxxxxxxxxxxxxxx> wrote:

I am working with the first dll I've ever created. I am testing with this
function:

bool DLLRect::PullWhisker(CString s)
{
if(s != _T("12345") )
::Beep(1000,200);
return true;
}

In my view:

DLLRect r;
r.PullWhisker(_T("12345") );

Why am I getting that beep, i.e. why is the string not recognized?

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



.



Relevant Pages

  • Re: passing a string to a dll
    ... I have, for now at least, chosen to use CString& in both the dll and the ... // DLLRect.h: ... Is the example you are using EXACTLY using the string "12345" or is it ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I have, for now at least, chosen to use CString& in both the dll and the application. ... // DLLRect.h: interface for the DLLRect class. ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I have now specified unicode in the dll, so it should match up with the ... I have, for now at least, chosen to use CString& in both the dll and the ... // DLLRect.h: interface for the DLLRect class. ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... avoid C++ as much as possible inside the DLL? ... An array is just ... I don't see any reason you can't use a CString, as long as you don't do static linking ... CString LoadStringID(UINT stringID); ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... These comments about LPCTSTR in the DLL, how much do they apply to a shared ... build the array with LPCTSTR instead of CString? ... CString LoadStringID(UINT stringID); ...
    (microsoft.public.vc.mfc)