Yagirobi
February 2nd, 2005, 08:50 AM
I have a C++ managed dll calling an unmanaged dll. The unmanaged dll has a
class library that I want to export. I'm having a problem with marshalling. I
reproduced the problem in a small example below. CBSTRUnmanaged is the
unmanaged class and ManagedBSTR is the managed class.
/*
Here's the unmanaged header file:
*/
#pragma once
class __declspec(dllexport) CBSTRUnmanaged
{
public:
CBSTRUnmanaged();
~CBSTRUnmanaged();
void SetCommPort(short nNewValue);
short GetFirmwareVersion(BSTR FAR* pSignature, BSTR FAR* pName, BSTR FAR*
pVersion);
};
/*
Here's the version of the unmanaged header file that I include in the managed
code:
*/
using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices;
class __declspec(dllimport) CBSTRUnmanaged
{
public:
CBSTRUnmanaged();
~CBSTRUnmanaged();
void SetCommPort(short nNewValue);
short GetFirmwareVersion([MarshalAs (UnmanagedType::BStr) ]StringBuilder*
pSignature,[MarshalAs (UnmanagedType::BStr) ]StringBuilder* pName,[MarshalAs
(UnmanagedType::BStr)]StringBuilder* pVersion);
};
/*
Here's the managed header file, its member function GetFirmwareVersion calls
the unmanaged GetFirmwareVersion:
*/
using namespace System;
#include "BSTRUnmanaged.h"
#pragma once
namespace ManagedBSTRspace
{
public __gc class ManagedBSTR
{
ManagedBSTR();
~ManagedBSTR();
short GetFirmwareVersion(StringBuilder* pSignature,StringBuilder* pName,
StringBuilder* pVersion);
void SetCommPort(short nNewValue);
CBSTRUnmanaged __nogc* unmanagedBSTRptr;
};
}
/*
The linker gives the error:
ManagedBSTR error LNK2001: unresolved external symbol "public: short
__thiscall CBSTRUnmanaged::GetFirmwareVersion(class
System::Text::StringBuilder __gc *,class System::Text::StringBuilder __gc
*,class System::Text::StringBuilder __gc *)"
(?GetFirmwareVersion@CBSTRUnmanaged@@$$FQAEFP$AAVStringBuilder@Text@System@@00
@Z)
*/
Why isn't MarshalAs changing the external parameter symbol from StringBuilder
to BSTR? Thanks.
Leon
class library that I want to export. I'm having a problem with marshalling. I
reproduced the problem in a small example below. CBSTRUnmanaged is the
unmanaged class and ManagedBSTR is the managed class.
/*
Here's the unmanaged header file:
*/
#pragma once
class __declspec(dllexport) CBSTRUnmanaged
{
public:
CBSTRUnmanaged();
~CBSTRUnmanaged();
void SetCommPort(short nNewValue);
short GetFirmwareVersion(BSTR FAR* pSignature, BSTR FAR* pName, BSTR FAR*
pVersion);
};
/*
Here's the version of the unmanaged header file that I include in the managed
code:
*/
using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices;
class __declspec(dllimport) CBSTRUnmanaged
{
public:
CBSTRUnmanaged();
~CBSTRUnmanaged();
void SetCommPort(short nNewValue);
short GetFirmwareVersion([MarshalAs (UnmanagedType::BStr) ]StringBuilder*
pSignature,[MarshalAs (UnmanagedType::BStr) ]StringBuilder* pName,[MarshalAs
(UnmanagedType::BStr)]StringBuilder* pVersion);
};
/*
Here's the managed header file, its member function GetFirmwareVersion calls
the unmanaged GetFirmwareVersion:
*/
using namespace System;
#include "BSTRUnmanaged.h"
#pragma once
namespace ManagedBSTRspace
{
public __gc class ManagedBSTR
{
ManagedBSTR();
~ManagedBSTR();
short GetFirmwareVersion(StringBuilder* pSignature,StringBuilder* pName,
StringBuilder* pVersion);
void SetCommPort(short nNewValue);
CBSTRUnmanaged __nogc* unmanagedBSTRptr;
};
}
/*
The linker gives the error:
ManagedBSTR error LNK2001: unresolved external symbol "public: short
__thiscall CBSTRUnmanaged::GetFirmwareVersion(class
System::Text::StringBuilder __gc *,class System::Text::StringBuilder __gc
*,class System::Text::StringBuilder __gc *)"
(?GetFirmwareVersion@CBSTRUnmanaged@@$$FQAEFP$AAVStringBuilder@Text@System@@00
@Z)
*/
Why isn't MarshalAs changing the external parameter symbol from StringBuilder
to BSTR? Thanks.
Leon