Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6596787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:07:18+00:00 2026-05-25T18:07:18+00:00

The first piece of code is the example i am working on, after changing

  • 0

The first piece of code is the example i am working on, after changing it to the second example, it works exept for the __declspec(dllexport) wich gives a __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention. removing that piece of code does make the dll compile but the method is unavaible to the target dll. Also when i use PE Explorer to look into the DLL there are no export methods. Is there a managed variant for the __declspec(dllexport)?

extern "C" __declspec(dllexport) int UserInstruction (HWND hWnd,
                              HINSTANCE hInst,
                              double FAR *Function, 
                              char FAR *Str1,
                              char FAR *Str2)
{
       strcpy(Str1, "TEST FUNCTION");
       return (TRUE);
}


extern "C" __declspec(dllexport) int UserInstruction (IntPtr hWnd, IntPtr hInst, double *Function, char *Str1, char *Str2)
{
    Str1 = "TEST FUNCTION";
    return (true);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:07:19+00:00Added an answer on May 25, 2026 at 6:07 pm

    The C++/CLI compiler does support exporting managed functions. It automatically generates a thunk that loads and initializes the CLR if necessary so that the managed code can be executed. Beware the overhead. You however can’t use any managed types for the function arguments. IntPtr in your case. That doesn’t make sense, the unmanaged code that calls your function won’t be using managed types.

    You’ll have to marshal them yourself. Not a problem here, these are pointers so you can simply cast to IntPtr:

    extern "C" __declspec(dllexport) 
    int __stdcall UserInstruction (HWND hWnd, HINSTANCE hInst, double FAR *Function, char FAR *Str1, char FAR *Str2)
    {
        IntPtr windowPtr = (IntPtr)hWnd;
        IntPtr instancePtr = (IntPtr)hInst;
        // etc..
    }
    

    Explicitly selecting the calling convention is always a good idea. I added __stdcall for that reason, the most common one for exported DLL functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, will the first piece of code perform a full search twice, or
Saw this piece of code in a Ruby on Rails book. This first one
Is there way in next piece of code to only get the first record?
Firstly sorry for the long piece of code pasted below. This is my first
I am working on a piece of code that writes data from 4 different
I'm working on a piece of code in C# / XNA where I'm highly
Can anyone give me the example code that I can use to first present
I have a mostly-working piece of code to read a directory, output each folder
I try to display a Toast inside a AsyncTask. This first piece of code
I'm writing my first proper useful piece of software. Part of it will involve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.