我尝试在我的c#控制台应用程序中绑定http://msdn.microsoft.com/en-us/library/ms235636.aspx中显示的简单c ++ dll ,但是在运行时我在dll中得到了一个EntryPointNotFoundException.我的测试课是
namespace BindingCppDllExample
{
public class BindingDllClass
{
[DllImport("MathFuncsDll.dll")]
public static extern double Add(double a, double b);
}
public class Program
{
public static void Main(string[] args)
{
double a = 2.3;
double b = 3.8;
double c = BindingDllClass.Add(a, b);
Console.WriteLine(string.Format("{0} + {1} = {2}", a, b, c));
}
}
}
Run Code Online (Sandbox Code Playgroud)
什么是不正确的?
我正在尝试在我的应用程序中设置系统环境变量,但得到一个SecurityException.我测试了我在谷歌找到的所有内容 - 没有成功.这是我的代码(注意,我是我的电脑的管理员,并以管理员身份运行VS2012):
尝试1
new EnvironmentPermission(EnvironmentPermissionAccess.Write, "TEST1").Demand();
Environment.SetEnvironmentVariable("TEST1", "MyTest", EnvironmentVariableTarget.Machine);
Run Code Online (Sandbox Code Playgroud)
尝试2
new EnvironmentPermission(EnvironmentPermissionAccess.Write, "TEST1").Demand();
using (var envKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true))
{
Contract.Assert(envKey != null, @"HKLM\System\CurrentControlSet\Control\Session Manager\Environment is missing!");
envKey.SetValue("TEST1", "TestValue");
}
Run Code Online (Sandbox Code Playgroud)
你有什么其他的建议?
有人可以解释一下shift这个iMA函数的两个参数之间的区别是什么?
根据MQL4文件:
ma_shift- 移动平均移动.指标线偏移与时间范围的图表相关.
shift- 从指标缓冲区获取的值的索引(相对于当前条的转移给定的前期数)
标准MA指标采用哪些参数?
如何在执行命令字符串时使用表变量?
DECLARE @FileIDs TABLE
(
File_ID int
)
insert into @FileIDs select ID from Files where Name like '%bla%';
DECLARE @testquery as varchar(max);
set @testquery = 'select * from @FileIDs';
exec(@testquery);
Run Code Online (Sandbox Code Playgroud)
返回以下错误
消息 1087,级别 15,状态 2,第 1 行 必须声明表变量“@FileIDs”。
由于 VS2008 类 bad_alloc 不提供带有字符串参数的构造函数。有没有可能在不覆盖这样的类的情况下创建自定义消息?
// this is only pseudo-code
class custom_exception : bad_alloc {
public:
string Message;
custom_exception(string m) {Message = m;}
}
Run Code Online (Sandbox Code Playgroud) 我试图从静态库中使用内联函数,但我得到了
error LNK2019: unresolved external symbol _ippsExp_64f@12 referenced in function "double __cdecl IppExp(double const &)" (?IppExp@@YANABN@Z)
这是我的代码:
IppWrapper.h(项目A)
#include <ippcore.h>
#include <ipps.h>
#include <ippvm.h>
inline double IppExp(const double& a)
{
Ipp64f y;
IppStatus s = ippsExp_64f(&a, &y, 1);
return y;
}
Run Code Online (Sandbox Code Playgroud)
main.cpp(添加了A.lib)
#include "IppWrapper.h"
int main()
{
double d = IppExp(2.3);
}
Run Code Online (Sandbox Code Playgroud)
dumpbin /symbols也没有收到我的功能.我错过了什么?
在我所在的类中,重构析构函数不会破坏其数组.
class MyClass{
public:
double a;
double rect[4];
MyClass();
~MyClass();
};
MyClass::MyClass() : a(123.0)
{
memset(rect, 0, 4 * sizeof(double));
}
MyClass::~MyClass() {}
Run Code Online (Sandbox Code Playgroud)
我该如何正确销毁它?是否delete足够简单或者我还需要设置以下内容?
delete[] rect;
*rect= NULL;
Run Code Online (Sandbox Code Playgroud) 我有一个组合框,我在其中放置了CListCtrl一个自定义高度
m_FeatureList.GetClientRect(&rect);
nColInterval = rect.Width()/2;
m_FeatureList.InsertColumn(0, _T("ID"), LVCFMT_LEFT, nColInterval);
m_FeatureList.InsertColumn(1, _T("Class"), LVCFMT_RIGHT, nColInterval);
m_FeatureList.ModifyStyle( LVS_OWNERDRAWFIXED, 0, 0 );
m_FeatureList.SetExtendedStyle(m_CoilList.GetExtendedStyle() | LVS_EX_GRIDLINES);
...
int a, b;
m_FeatureList.GetItemSpacing(true, &a, &b);
// data is a vector containing item text
m_FeatureList.MoveWindow(listRect.left, listRect.top, listRect.Width(), b*data.size()+4);
int i = 0;
std::for_each(data.begin(), data.end(), [&](CString& p) { AddDefectListItem(i++,p); });
Run Code Online (Sandbox Code Playgroud)
现在我想在下方放置一个图片控件CListCtrl,但所有功能都让CRect我感到困惑.所有他们把控制放在某处但不是我想要的地方.
//m_FeatureList.GetClientRect(&listRect);
//m_FeatureList.ClientToScreen(&listRect);
m_FeatureList.ScreenToClient(&listRect);
// Oh my god, which coordinates do I need???
m_image.MoveWindow(listRect.left, listRect.bottom+3,listRect.Width(), 20);
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个疯狂的mfc问题吗?
是否可以在C++中创建同一个类的子成员?就像是
class A
{
public:
int i;
A child;
};
Run Code Online (Sandbox Code Playgroud)
提前致谢.
在表格上我有一个带有一些按钮的面板.单击button1时,我将面板替换为具有标签的新UserControl(例如this.Controls.Clear(),this.Controls.Add(UserControl1)).除了我的userControl上的标签有一个KeyDown处理程序.它工作正常,事件触发,但不是键,向上,向下,向左和向右.任何人都可以解释为什么这些键之间存在差异?是什么决定事件是否被解雇?
是否可以导出包装类的结构而不包装它(结构仅包含枚举和基元)?假设我的包装如下所示:
WorkerWrapper.h
#ifdef TESTEXPORTDLL_EXPORTS
#define TESTEXPORTDLL_API __declspec(dllexport)
#else
#define TESTEXPORTDLL_API __declspec(dllimport)
#endif
class Worker;
struct JobTypeInfo;
template class TESTEXPORTDLL_API std::unique_ptr<Worker>;
class TESTEXPORTDLL_API WorkerWrapper {
private:
std::unique_ptr<Worker> fWorker;
public:
WorkerWrapper();
~WorkerWrapper();
WorkerWrapper(WorkerWrapper&& aThat);
WorkerWrapper& operator= (WorkerWrapper&& aThat);
void DoJob(JobTypeInfo aTypeInfo);
};
Run Code Online (Sandbox Code Playgroud)
这是通过使用WorkerWrapper.cpp定期实现的处理,这不是我问题的原因。该类是前向声明的,并包含一个我想要导出的结构。unique_ptrstd::moveWorkerWorkerWrapper
工人.h
struct JobTypeInfo
{
typedef enum
{
DoThis,
DoThat,
DoNothing
} CalcType;
CalcType sCalcType;
//... primitives
};
class Worker
{
public:
void DoJob(JobTypeInfo aTypeInfo);
};
Run Code Online (Sandbox Code Playgroud)
我在这里能做什么?
提前致谢。