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;
}
==================================================================
解决方案 »
- 我用CRectTracker实现了拖动直线矩形,可是拖动曲线多边形却不行
- 郁~~闷 网络书籍如此的多 不知道网络编程该看什么书和什么学习方法?
- 求问原理或代码
- 关于hwnd和process_information
- 一个多线程socket程序,正常运行约10天就出现“初始化失败”的对话框? 捆扰!!!
- 关于线程中分配资源的释放问题.
- vs2012 (rc) + windows8 (release preview)dll工程引用问题,vs2010无此问题 --结局
- 大家别笑我菜,我想知道你们都在开发社什么!
- 谁能帮我????OpenGL....
- 谁能解密PDF格式,给分给钱都可以!
- 如何在客户端发也指令通过服务器对数据库进行操作??
- 键盘消息
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);