Results 1 to 4 of 4

Thread: [RESOLVED] VC++ DLL and exporting __cpuid and __cpuidex

  1. #1

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Resolved [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!
    My Blog.

    Ryan Jones.

  2. #2

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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.
    My Blog.

    Ryan Jones.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] VC++ DLL and exporting __cpuid and __cpuidex

    Post what you did.

  4. #4

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: [RESOLVED] VC++ DLL and exporting __cpuid and __cpuidex

    Of course.

    C++ Code:
    1. struct CPUInfo
    2. {
    3.     int EAX;
    4.     int EBX;
    5.     int ECX;
    6.     int EDX;
    7. };
    8.  
    9. extern "C" __declspec(dllexport) CPUInfo cpuID(int infoType)
    10. {
    11.     CPUInfo i;
    12.  
    13.     int results[4] = { 0, 0, 0, 0 };
    14.  
    15.     __try
    16.     {
    17.         __cpuid(results, infoType);
    18.     }
    19.     __except (EXCEPTION_EXECUTE_HANDLER) {}
    20.  
    21.     i.EAX = results[0];
    22.     i.EBX = results[1];
    23.     i.ECX = results[2];
    24.     i.EDX = results[3];
    25.  
    26.     return i;
    27. }

    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.
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width