J
Jason W
I have a C# class that I wan't to be able to use in VB6 and VBA
applications. To do this I was trying to use a mixed managed VC++ dll and
export a function. Doing this I get an error "The memory could not be
"read"".
Can any one explain what I am doing wrong?
This is my Code.
..CPP
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Collections;
using namespace WdCadTmInfo;
#define WDINFO_LINKAGE __declspec(dllexport)
#include "PlotAccounting-C.h"
__gc class ManagedObjects{
public:
};
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
extern "C"{
WDINFO_LINKAGE char* getWdInfo(char* Param){
wdCadTeamInfo* tmpInfo = new wdCadTeamInfo();
IntPtr ptr = Marshal::StringToHGlobalAnsi(tmpInfo->GetWdCadTmInfo(Param));
char __nogc* pStr = static_cast<char*>(ptr.ToPointer());
Marshal::FreeHGlobal(ptr);
return pStr;
}
}
..H
#ifndef WDINFO_LINKAGE
#define WDINFO_LINKAGE __declspec(dllimport)
#endif
extern "C"{
WDINFO_LINKAGE char* getWdInfo(char* Param);
}
applications. To do this I was trying to use a mixed managed VC++ dll and
export a function. Doing this I get an error "The memory could not be
"read"".
Can any one explain what I am doing wrong?
This is my Code.
..CPP
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Collections;
using namespace WdCadTmInfo;
#define WDINFO_LINKAGE __declspec(dllexport)
#include "PlotAccounting-C.h"
__gc class ManagedObjects{
public:
};
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
extern "C"{
WDINFO_LINKAGE char* getWdInfo(char* Param){
wdCadTeamInfo* tmpInfo = new wdCadTeamInfo();
IntPtr ptr = Marshal::StringToHGlobalAnsi(tmpInfo->GetWdCadTmInfo(Param));
char __nogc* pStr = static_cast<char*>(ptr.ToPointer());
Marshal::FreeHGlobal(ptr);
return pStr;
}
}
..H
#ifndef WDINFO_LINKAGE
#define WDINFO_LINKAGE __declspec(dllimport)
#endif
extern "C"{
WDINFO_LINKAGE char* getWdInfo(char* Param);
}