What do I describe code of loading dynamic dll by C++/CX?

nippy 45 Reputation points
2023-12-13T07:34:26.2333333+00:00

Hello! I learn describing code of loading dynamic dll by C++/CX. What do I describe code of loading dynamic dll by C++/CX? Please describe sample code.

Developer technologies Universal Windows Platform (UWP)
Developer technologies C++
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2023-12-15T06:19:51.36+00:00

    Hi @nippy ,

    UWP C++/CX can load win32 and UWP dynamic DLL. Here are my test steps:

    DLL(Win32 or UWP)

    User's image

    1. Create DLL project, name "DllTest".
    2. Add extern "C" content in "Pch,h".
    extern "C"
    {    
       _declspec(dllexport) void mainDll(double a, double b, double* aplusb);
    }
    
    1. Add function content in "Pch.cpp".
    #include "pch.h"
    void mainDll(double a, double b, double* aplusb)
    {    
      *aplusb = a + b;
    }
    
    1. Rebuild the project, find the dll file in output file, copy it to the AppX file of UWP project. It is recommended to modify the Output Directory. User's image

    UWP(C++/CX):

    1. Create UWP C++/CX project, its name is App2.
    2. Add code about calling the dll.
    HINSTANCE hDLL = LoadLibrary(L"DllTest.dll"); 
    typedef void (*func)(double a, double b, double* aplusb); 
    func callDll = (func)GetProcAddress(hDLL, "mainDll"); 
    double a = 1, b = 2, result;
    callDll(a, b, &result);
    
    1. Check the value of result, it should be 3.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.