ClassInDLL.h
==================================================================
#ifndef ClassInDLL_H
#define ClassInDLL_H#ifdef _CLASSINDLL
#define CLASSINDLL_CLASS_DECL __declspec(dllexport)
#else
#define CLASSINDLL_CLASS_DECL __declspec(dllimport)
#endif#endif // ClassInDLL_H
==================================================================InDLL.h
==================================================================
// InDLL.h: interface for the CInDLL class.
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_INDLL_H__179A79AA_4C1A_11D2_B67C_006008AC62A9__INCLUDED_)
#define AFX_INDLL_H__179A79AA_4C1A_11D2_B67C_006008AC62A9__INCLUDED_#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000#include "ClassInDLL.h"
#include <comutil.h>class CLASSINDLL_CLASS_DECL CInDLL
{
public:
CInDLL();
virtual ~CInDLL(); bstr_t Test_bstr();
char* Test_charstar();};#endif // !defined(AFX_INDLL_H__179A79AA_4C1A_11D2_B67C_006008AC62A9__INCLUDED_)
==================================================================InDLL.cpp
==================================================================
// InDLL.cpp: implementation of the CInDLL class.
//
//////////////////////////////////////////////////////////////////////#include "InDLL.h"//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////CInDLL::CInDLL()
{}CInDLL::~CInDLL()
{}bstr_t CInDLL::Test_bstr()
{
bstr_t temp;
temp = "Test!";
return temp;
}char* CInDLL::Test_charstar()
{
bstr_t temp;
temp = "Test!";
return _com_util::ConvertBSTRToString(temp);
}
==================================================================**********************TestClassInDLL.cpp
==================================================================
#include "InDLL.h"
#include <comutil.h>int main()
{
bstr_t temp;
CInDLL classFromDLL;
temp = classFromDLL.Test_charstar();
temp = classFromDLL.Test_charstar(); //ok temp = classFromDLL.Test_bstr();
temp = classFromDLL.Test_bstr(); //error
return 0;
}
==================================================================
==================================================================
#ifndef ClassInDLL_H
#define ClassInDLL_H#ifdef _CLASSINDLL
#define CLASSINDLL_CLASS_DECL __declspec(dllexport)
#else
#define CLASSINDLL_CLASS_DECL __declspec(dllimport)
#endif#endif // ClassInDLL_H
==================================================================InDLL.h
==================================================================
// InDLL.h: interface for the CInDLL class.
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_INDLL_H__179A79AA_4C1A_11D2_B67C_006008AC62A9__INCLUDED_)
#define AFX_INDLL_H__179A79AA_4C1A_11D2_B67C_006008AC62A9__INCLUDED_#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000#include "ClassInDLL.h"
#include <comutil.h>class CLASSINDLL_CLASS_DECL CInDLL
{
public:
CInDLL();
virtual ~CInDLL(); bstr_t Test_bstr();
char* Test_charstar();};#endif // !defined(AFX_INDLL_H__179A79AA_4C1A_11D2_B67C_006008AC62A9__INCLUDED_)
==================================================================InDLL.cpp
==================================================================
// InDLL.cpp: implementation of the CInDLL class.
//
//////////////////////////////////////////////////////////////////////#include "InDLL.h"//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////CInDLL::CInDLL()
{}CInDLL::~CInDLL()
{}bstr_t CInDLL::Test_bstr()
{
bstr_t temp;
temp = "Test!";
return temp;
}char* CInDLL::Test_charstar()
{
bstr_t temp;
temp = "Test!";
return _com_util::ConvertBSTRToString(temp);
}
==================================================================**********************TestClassInDLL.cpp
==================================================================
#include "InDLL.h"
#include <comutil.h>int main()
{
bstr_t temp;
CInDLL classFromDLL;
temp = classFromDLL.Test_charstar();
temp = classFromDLL.Test_charstar(); //ok temp = classFromDLL.Test_bstr();
temp = classFromDLL.Test_bstr(); //error
return 0;
}
==================================================================
解决方案 »
- 散分贴 经验分享帖 关于调试远程线程的方法
- DLL 中函数析构的问题
- $$$谁给我讲解一下局部变量在函数返回之后就被销毁的具体含义
- 收藏 跪求答案,如何用程序实现以特定的用户名和密码登录windows.
- 有谁知道,为什么www.codeproject.com和www.codeguru.com的一些代码,不可以加断点调试,这是为什么呢?回答有分
- mfc中的预定义宏?
- 请问CPropertySheet的Create成员函数怎么使用?谢谢!!
- com还没有入门,但想做一个像Button,这一类的com组件
- 跟踪时,就弹出无数个窗口
- 多次动态创建按钮的问题 求大神指教啊
- 如何在客户端发也指令通过服务器对数据库进行操作??
- 键盘消息
bstr_t bStr = SysAllocString("test");
SysFreeString(bStr);
{
_bstr_t temp;
temp = "Test!";
*pbstr=temp.Detach();
}或者void CInDLL::Test_bstr(BSTR* pbstr)
{
*pbstr=SysAllocString(L"Test!");
}//调用时这样
_bstr_t temp; 或者 CComBSTR temp;
CInDLL classFromDLL;
classFromDLL.Test_bstr(&temp);