form调用C++写的dll正常,asp.net调用出错(dll会访问一些外部文件)
大家好,有个c++ 写的dll在form中调用正常,一摸一样的代码到asp.net中就不行了,dll会访问外部文件,被访问的文件我权限都给了,还是不行。
我把dll包在windows service中间也还是不行。
想请假大家一下,form中执行外部dll是不是有什么特殊的权限?着急啊,劳驾各位帮忙了!
------解决方案--------------------你可把dll进行再包装一层
Let 's do an experiment with inline assembly in a DLL. I can not call assembly language from C# but I know I can call unmanaged DLLs from C#. I 'll make a DLL which calculates the speed of CPU, vendor name, Family, Model and Stepping of CPU using in line assembly language.
Program 7
// SysInfo.cpp
// written by Zeeshan Amjad
#include "SysInfo.h "
BOOL __stdcall DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) {
return TRUE;
}
extern "C " __declspec(dllexport) int __stdcall getCPUSpeed() {
LARGE_INTEGER ulFreq, ulTicks, ulValue, ulStartCounter, ulEAX_EDX, ulResult;
// it is number of ticks per seconds
QueryPerformanceFrequency(&ulFreq);
// current valueofthe performance counter
QueryPerformanceCounter(&ulTicks);
// calculate one second interval
ulValue.QuadPart = ulTicks.QuadPart + ulFreq.QuadPart;
// read time stamp counter
// this asm instruction load the highorder 32 bit of the register into EDX
// and the lower order 32 bits into EAX
_asm {
rdtsc
mov ulEAX_EDX.LowPart, EAX
mov ulEAX_EDX.HighPart, EDX
}
// start no of ticks
ulStartCounter.QuadPart = ulEAX_EDX.QuadPart;
// loop for 1 second
do {
QueryPerformanceCounter(&ulTicks);
} while (ulTicks.QuadPart <= ulValue.QuadPart);
// get the actual no of ticks
_asm {
rdtsc
mov ulEAX_EDX.LowPart, EAX
mov ulEAX_EDX.HighPart, EDX
}
// calculate result
ulResult.QuadPart = ulEAX_EDX.QuadPart - ulStartCounter.QuadPart;
return (int)ulResult.QuadPart / 1000000;
}
extern "C " __declspec(dllexport) char* __stdcall getCPUType() {
static char pszCPUType[13];
memset(pszCPUType, 0, 13);
_asm {
mov eax, 0
cpuid
// getting information from EBX
mov pszCPUType[0], bl
mov pszCPUType[1], bh
ror ebx, 16
mov pszCPUType[2], bl
mov pszCPUType[3], bh
// getting information from EDX
mov pszCPUType[4], dl
mov pszCPUType[5], dh
ror edx, 16
mov pszCPUType[6], dl
mov pszCPUType[7], dh
// getting information from ECX
mov pszCPUType[8], cl
mov pszCPUType[9], ch
ror ecx, 16
mov pszCPUType[10], cl
mov pszCPUType[11], ch
}
pszCPUType[12] = '\0 ';
return pszCPUType;
}
extern "C " __declspec(dllexport) int __stdcall getCPUFamily() {
int retVal;
_asm {
mov eax, 1
cpuid
mov retVal, eax
}
return (retVal > > 8);
}
extern "C " __declspec(dllexport) int __stdcall getCPUModel() {
int retVal;
_asm {
mov eax, 1
cpuid
mov retVal, eax
}
return ((retVal > > 4 ) & 0x0000000f);
}
extern "C " __declspec(dllexport) int __stdcall getCPUStepping() {
int retVal;
_asm {
mov eax, 1
cpuid
mov retVal, eax
}
return (retVal & 0x0000000f);
}