[RESOLVED] VC++ DLL and exporting __cpuid and __cpuidex
Hi guys!
I need a little help here. I have experience with C++ but not in this sense. I'm trying to write a DLL that will export the above functions from a DLL file in VC++ so that I can gain access to them in C#.
I have no idea how this should be done so I'd appreciate some guidance on this issue.
Thanks!
Re: VC++ DLL and exporting __cpuid and __cpuidex
Actually. I think I have solved this myself - with a lot of fiddling it seems to work now.
Re: [RESOLVED] VC++ DLL and exporting __cpuid and __cpuidex
Re: [RESOLVED] VC++ DLL and exporting __cpuid and __cpuidex
Of course.
C++ Code:
struct CPUInfo
{
int EAX;
int EBX;
int ECX;
int EDX;
};
extern "C" __declspec(dllexport) CPUInfo cpuID(int infoType)
{
CPUInfo i;
int results[4] = { 0, 0, 0, 0 };
__try
{
__cpuid(results, infoType);
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
i.EAX = results[0];
i.EBX = results[1];
i.ECX = results[2];
i.EDX = results[3];
return i;
}
Pretty much the above. Then I created a copy of the class in C# and then called the function from the DLL via pinvoke. This is like the 3rd or 4th version of the code now that works.
I made a post about this on my blog for anyone who is interested in a little more detailed description.
Cheers.