【发布时间】:2015-03-11 06:17:49
【问题描述】:
我正在测试一个简单的 DLL,我使用 C++/CLI 在 CLR 控制台应用程序中编写。 DLL 只有一个我正在尝试使用的功能。我正在引用 DLL 并在项目属性页中设置 Resolve #using Reference,但我看不到我编写的函数。我猜我可能在某处错过了访问修饰符,但我不确定。这是我的代码的细分:
DLL 代码头:
// LogDLL.h
#pragma once
#using <mscorlib.dll>
using namespace System;
namespace LogDLL {
public ref class LogFuncs
{
// TODO: Add your methods for this class here.
LogFuncs(){;};
~LogFuncs(){;};
void log_to_file ( System::String ^file, bool overwrite, System::String ^text );
};
}
DLL 代码来源:
#include "stdafx.h"
#include "LogDLL.h"
using namespace System::Globalization;
void LogDLL::LogFuncs::log_to_file ( System::String ^file, bool overwrite, System::String ^text )
{
//Do Stuff
}
以及我正在使用的测试代码:
#include "stdafx.h"
#using <LogDLL.dll>
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
LogDLL::LogFuncs^ a;
a::LogDLL::LogFuncs:: //<-- Intellisense doesn't show the function from the DLL
return 0;
}
同样,我不确定我错过了什么。自从我使用 C++/CLI 以来已经有一段时间了,所以我很生疏。
更新:
我继续按照 Peter 的建议将类更改为结构。
修改后的 DLL 头代码:
// LogDLL.h
#pragma once
#using <mscorlib.dll>
using namespace System;
namespace LogDLL {
public ref struct LogFuncs
{
// TODO: Add your methods for this class here.
LogFuncs(){;};
~LogFuncs(){;};
void log_to_file ( System::String ^file, bool overwrite, System::String ^text );
};
}
我仍然不明白的是,为什么即使我将其指定为公共,该类仍会默认为私有。出现这种情况有什么根本原因吗?如果我使用非托管 C++ 会有什么不同吗??
【问题讨论】:
标签: .net visual-c++ c++-cli