BitScanForward64 issue in Visual Studio 11 Develop

2019-09-19 07:26发布

I am totally new to writing anything in C. I am writing a helper DLL (to be called from C#) that performs binary manipulation. I get an 'identifier "BitScanForward64" is undefined' error. The 32-bit version is available. I figure this is because I created a Win32 DLL.

It then dawned on me that the 64 bit version may only be available to a specific 64 bit DLL (I assume "General" on the new project wizard), and that I may need a separate 32 bit and 64 bit dll. Is this the case, or can I have a single DLL that runs both the BitScanForward and BitScanForward64 intrinsics, and if so, how do I go about creating it?

Here is my current code:

// C Functions.cpp : Defines the exported functions for the DLL application.

#include "stdafx.h"
//#include <intrin.h>
//#include <winnt.h>

int _stdcall LSB_i32(unsigned __int32 x)
{
    DWORD result;
    BitScanForward(&result, x);
    return (int)result;
}

int _stdcall MSB_i32(unsigned __int32 x)
{
    DWORD result;
    BitScanReverse(&result, x);
    return (int)result; 
}

int _stdcall LSB_i64(unsigned __int64 x)
{
    DWORD result;
    BitScanForward64(&result, x);
    return (int)result;
}

int _stdcall MSB_i64(unsigned __int64 x)
{
    DWORD result;
    BitScanReverse64(&result, x);
    return (int)result;
}

1条回答
聊天终结者
2楼-- · 2019-09-19 08:00

It is possible to create a DLL to hold both these operations, but it would then be an x64 only DLL (and thus usable only on a 64-bit OS in a 64-bit process), as shown in the table here (also note that the intrisics have an _ prefixed to them, the BitScan*64 functions might require this, they all work with it regardless).

This link details creating a x64 based project in Visual Studio, from which you should be able to create your dll.

查看更多
登录 后发表回答