我正在一个未记录的DLL中调用一个函数来解压缩文件.
标头声明/分配的方式一定有错,但无法弄清楚出了什么问题.
VS 2010中的项目字符集是Unicode.
可以使用下面的代码段从C#成功调用DLL函数(但我需要使它在c ++中工作):
[DllImport("unpacker.dll", EntryPoint = "UnpackFile", PreserveSig = false)]
internal static extern IntPtr UnpackFile(byte[] file, int fileSize,
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder header, int headerSize);
Run Code Online (Sandbox Code Playgroud)
如果我取消注释移动一个标题,则弹出一个Acccess Violation.该函数也返回0,它不在C#中.
有什么想法吗?
VC++ 2010项目中的代码:
// unpacker.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <fstream>
using namespace std;
typedef void* (*UnpackFile)(unsigned char*, int, LPTSTR, int);
int _tmain(int argc, _TCHAR* argv[])
{
LPTSTR header;
//Move this and get a access violation on the _UnpackFile(filetounpack... line
static unsigned …Run Code Online (Sandbox Code Playgroud)