小编Ben*_*min的帖子

构建64位dll的警告

DLL导出标题

extern "C"
void _declspec(dllexport) __stdcall foo();
Run Code Online (Sandbox Code Playgroud)

.def文件

EXPORTS
foo         @1
Run Code Online (Sandbox Code Playgroud)

当我通过64位构建配置构建dll时,我遇到了这个警告.

警告LNK4197:多次指定导出'foo'; 使用第一个规范

但是,如果我通过32位构建配置构建dll,则警告永远不会发生.
问题是什么?有什么不同.

在接口的dll头文件中,我们通常使用这个技术,

#ifdef EXPORT_DLL
#define BASICAPI _declspec(dllexport)
#else
#define BASICAPI _declspec(dllimport)
#endif //_EXPORT_DLL
Run Code Online (Sandbox Code Playgroud)

但是如果def文件也存在,我们总是会在构建64位dll时遇到警告.
那么,我们应该写这样的代码吗?

#ifdef EXPORT_DLL
#define BASICAPI
#else
#define BASICAPI _declspec(dllimport)
#endif //_EXPORT_DLL
Run Code Online (Sandbox Code Playgroud)

它运作良好.但这对我来说并不熟悉.
给我你的意见.

windows dll dllimport dllexport visual-studio

9
推荐指数
2
解决办法
3831
查看次数

为什么在这里使用static_cast而不是reinterpret_cast很重要?

在Raymond Chen的博客文章的回复中,

一位提问者指出

Raymond,我认为C++示例不正确,因为根据ISO C++ 2003 Standard(10-3,第168页)未定义派生类中基类子对象的位置,并且您假设基类子对象始终位于一开始.C语言中的C语言也没问题,所以我坚持下去.

雷蒙德回答说

[代码没有做出这个假设.这就是使用static_cast而不是reinterpret_cast的重要原因.试一试:向OVERLAPPED添加一个虚方法(所以vtable在前面)并观察编译器的作用.-Raymond]

读完他的评论后,我猜错了.在示例中使用static_cast很好,但是reinterpret_cast不是.因为reinterpret_cast不能转换为vtable.我理解得对吗?
虽然,如果我在那里使用C-Style演员(不是reinterpret_cast),它也会出错吗?

我重新阅读了更有效的C++演员解释,以了解这一点.但是没有答案.

c++ pointers casting static-cast reinterpret-cast

9
推荐指数
1
解决办法
2204
查看次数

std :: function如何知道调用约定?

int __cdecl ccall(int i)
{
    wprintf(L"ccall(%d)", i);
    return 0;
}

int __stdcall stdcall(int i)
{
    wprintf(L"stdcall(%d)", i);
    return 0;
}

int __cdecl wmain(int argc, wchar_t **argv)
{
    std::function<int(int)> fnc = ccall;
    std::function<int(int)> fnstd = stdcall;

    fnc(10); // printed well
    fnstd(100); // printed well
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我担心我怎么分配__stdcall functionstd::function对象.但是没有任何指定调用约定,它看起来好像工作.怎么std::function知道调用约定是什么?

c++ calling-convention c++11

9
推荐指数
1
解决办法
3049
查看次数

How to create a Junction Point using WinApi?

There is CreateHardLink function to create Hardlinks.(Since Win2000)
And there is CreateSymbolicLink function since Vista has been released.

But why isn't there a CreateJunction?

How does mklink make a junction?
And How do I write codes to make junction in my app?

windows filesystems ntfs junction

8
推荐指数
2
解决办法
4454
查看次数

我们应该使用_In_而不是__in吗?

我今天读到了VS.h中的sal.h.
我有点惊讶.

// This section contains the deprecated annotations
|------------|------------|---------|--------|----------|----------|---------------|
|   Level    |   Usage    |  Size   | Output | NullTerm | Optional |  Parameters   |
|------------|------------|---------|--------|----------|----------|---------------|
| <>         | <>         | <>      | <>     | _z       | <>       | <>            |
| _deref     | _in        | _ecount | _full  | _nz      | _opt     | (size)        |
| _deref_opt | _out       | _bcount | _part  |          |          | (size,length) |
|            | _inout     |         |        |          |          |               |
|            | …
Run Code Online (Sandbox Code Playgroud)

windows annotations visual-studio-2010 visual-c++

7
推荐指数
1
解决办法
3570
查看次数

如何替换某些范围的std :: vector的数据

std::vector<char> v;
v.push_back('a');
v.push_back('b');
v.push_back('c');
v.push_back('d');
v.push_back('e');
v.push_back('f');

char c[3] = { 'z', 'x', 'y' };

// Want to make abzxyf
//v.insert(v.begin() + 2, c, c + 3); // it doesn't work as I wanted.

// Yes it works. but if c is more bigger, it will be crash.
std::copy(c, c + 3, v.begin() + 2);

v.clear();
v.push_back('a');
v.push_back('b');
v.push_back('c');
v.push_back('d');
v.push_back('e');
v.push_back('f');

// If vector needs more memory, I'd let him grow automactically
// So I tried this.(expected abcdezxy) …
Run Code Online (Sandbox Code Playgroud)

c++ containers stl

7
推荐指数
1
解决办法
3112
查看次数

如何使Process Explorer的功能"替换任务管理器"?

Process Explorer有一个很好的功能替换任务管理器

在此输入图像描述

我只是想知道Mark Russinovich是如何实现这一点的.
用什么技巧来实现这个?

windows winapi sysinternals win32-process process-explorer

7
推荐指数
1
解决办法
1442
查看次数

Win32自定义消息框

我想制作一个自定义消息框.我想要自定义的是按钮的文本.

MessageBoxW(
  NULL,
  L"Target folder already exists. Do you want to overwrite the folder?",
  L"No title",
  MB_YESNOCANCEL | MB_ICONQUESTION
  );
Run Code Online (Sandbox Code Playgroud)

我想按钮文本只是改变到Overwrite,Skip,Cancel.
什么是最简单的方法?

我必须使其与Windows默认消息框具有相同的外观和感觉.

windows hook user-interface winapi subclass

7
推荐指数
1
解决办法
6267
查看次数

'Mutex锁'究竟做了什么?

您可以在此链接中看到一个有趣的表格.http://norvig.com/21-days.html#answers

该表描述了
Mutex 从主内存中锁定/解锁25 nanosec
100 nanosec

纳秒?
我很惊讶因为mutex lock速度比fetch data from memory.如果是这样,到底mutex lock是做什么的?Mutex lock桌上的意思是什么?

operating-system kernel mutex locking

7
推荐指数
2
解决办法
3729
查看次数

如何在没有ActiveX的情况下直接在网页上安装Google Chrome

它有魔力吗?
当我点击网页上的下载按钮时,会下载并安装Google Chrome.
它不使用ActiveX.它甚至不需要在Vista或更高版本中使用UAC窗口.
怎么可能?

请让我知道如何做到这一点.
我想让我的程序像这样.

windows installation installer google-chrome

6
推荐指数
1
解决办法
1218
查看次数