|
-
May 19th, 2010, 12:46 PM
#1
Thread Starter
Frenzied Member
[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!
-
May 19th, 2010, 03:39 PM
#2
Thread Starter
Frenzied Member
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.
-
Jun 9th, 2010, 11:04 AM
#3
Re: [RESOLVED] VC++ DLL and exporting __cpuid and __cpuidex
-
Jun 9th, 2010, 12:00 PM
#4
Thread Starter
Frenzied Member
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.
Last edited by sciguyryan; Jun 9th, 2010 at 12:28 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|