Access 3rd web services from c++ MFC


I need to access our developed web services from PW explorer.

I took example project from SDK library -  docprop. I would like to have a possibility have a button which connect to my web services and get some information from there.

In C# i use code like this, but can't find how to make run it on C++ with MFC.

The other option is create command in C# for PW explorer, but i do not know how to this as well.



using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
client.BaseAddress = new Uri(sDomain);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(scheme, pass);
String sApiPath = "/master-tables";
HttpResponseMessage response = client.GetAsync(sApiPath).Result;
string result = response.Content.ReadAsStringAsync().Result;
List<MasterTable> prTables = JsonConvert.DeserializeObject<List<MasterTable>>(result);

foreach (MasterTable t in prTables)
if ( == true)
String sApiPathTr = "/master-tables/" + t.masterTableId + "/records";
HttpResponseMessage responseTr = client.GetAsync(sApiPathTr).Result;
string resultTr = responseTr.Content.ReadAsStringAsync().Result;
ReadMasterTableFromCodes = JsonConvert.DeserializeObject<List<TableRecord>>(resultTr);

Parents Reply Children
  • Darius,

    I don't know if there are MFC tools available to do what you want to do, but I suspect that you can do all that you want to do with C++, but you will have to do some "research" into the means to do so.

    If you already have working C# code, and are more comfortable using C# and .NET, then there isn't really anything from stopping you to use both, you just need to have a way to invoke the C# code from PW Explorer, which of course is unmanaged code.  Using the DllExporterNet4 tool makes this relatively easy to do.

    If you want to call your C# code from a PW menu, trying this approach:

    • Use the Menu Editor to create an MRR file that specifies C++ coded functions
    • Have your C++ menu functions call your C# code exported with the DllExporterNet4 tool

    I have personally used this approach and the advantage is that you can keep the C++ code pretty minimal while taking advantage of the C#.NET development environment to implement whatever it is that you already know how to make work.


  • Hi,

    Thank you for pointing me to the right direction, appreciate it.

    Sorry, but I do not understand what I do wrong.

    I have done simple C# dll and try follow by instruction.


    Install-Package DllExporterNet4X64 -Version 1.0.0

    There is my C# code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Exportteddll
    public class ExportedDll

    static void test ( )

    On post build I have added.

    DllExporterNet4X64.exe $(TargetFileName)
    move $(TargetName).Exports$(TargetExt) $(TargetFileName)

    on build I has got error message.

    Severity Code Description Project File Line Suppression State
    Error The command "DllExporterNet4X64.exe Exportteddll.dll
    move Exportteddll.Exports.dll Exportteddll.dll" exited with code 1. ExportedDll

    Best regards


  • Hi,

    Maybe you have some example. I need something for startup.

    Thank you.


  • I think you probably have to define your static method as public, but the problem reported appears to be in your post build commands.  Perhaps using 'move' is the problem?  FWIW, I always copy the modified DLL file, typically with something like this:

    echo "Executing DllExporterNet4.exe $(TargetFileName)..."
    DllExporterNet4.exe $(TargetFileName)
    echo "copy $(TargetName).Exports$(TargetExt) $(TargetFileName)..."
    copy $(TargetName).Exports$(TargetExt) $(TargetFileName)
    echo "copy $(TargetFileName) "$(PWBIN)"..."
    copy $(TargetFileName) "$(PWBIN)"

    Now depending upon how you have coded all of this, you might have to load your DLL yourself before attempting to call your exported function.

    Also, you should be using the x86 version of DllExporterNet4 since this is for ProjectWise Explorer, which is an x86 application.

  • Here's some sample c# code that you can call from a .mrr file.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Diagnostics;
    using System.Data;
    using DllExporterNet4;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    namespace ManagedCodeCalledFromMrr
        public class MyManagedCode
            public static int MyDocCmdInManagedCode
                uint uiCount, //==>Count of documents 
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]int[] plProjArray, //==>Project number Array
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]int[] plDocArray //==> Document number Array
                string msg = string.Empty;
                // Select first document's properties
                long retValue = PWWrapper.aaApi_SelectDocument(plProjArray[0], plDocArray[0]);
                if (retValue == 1)  // document exists
                    String DocName = PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.Name, 0);
                    msg = string.Format("Selected Document Count is {0}", uiCount) +
                        string.Format("\nFirst Document name is '{0}'", DocName);
                else if (retValue == -1)    // error
                    msg = string.Format("[{0}]\n{1}\n{2}",
                else  // document does not exist
                    msg = string.Format("Document does not exist!");
                MessageBox.Show(msg, "ManagedCodeCalledFromMrr", MessageBoxButtons.OK);
                return 0;

    Here's how I used DllExporterNet4 in a post build step:

    echo "Executing DllExporterNet4.exe $(TargetFileName)..."
    DllExporterNet4.exe $(TargetFileName)
    echo copying $(TargetName).Exports$(TargetExt) to $(TargetFileName)...
    copy $(TargetName).Exports$(TargetExt) $(TargetFileName)
    echo copying x$(TargetFileName) to $(PWBinx86Dir)...
    copy $(TargetFileName) "$(PWBinx86Dir)"
    echo Copying $(SolutionDir)Menus\*.mrr  to "$(PWBinx86Dir)"...
    Copy "$(SolutionDir)Menus\*.mrr " "$(PWBinx86Dir)"

    And here's a PowerShell script to create the macros that I use (primarily with C++ projects):

    [Environment]::SetEnvironmentVariable("PWBinx86Dir", "C:\Program Files (x86)\Bentley\ProjectWise\bin\", "Machine")
    [Environment]::SetEnvironmentVariable("PWIncludeX86Dir", "C:\Program Files\Bentley\ProjectWise\SDK\include\", "Machine")
    [Environment]::SetEnvironmentVariable("PWLibx86Dir", "C:\Program Files\Bentley\ProjectWise\SDK\lib\Win32\", "Machine")
    [Environment]::SetEnvironmentVariable("PWRsrcx86Dir", "C:\Program Files (x86)\Bentley\ProjectWise\rsrc\", "Machine")
    [Environment]::SetEnvironmentVariable("PWSDKx86Dir", "C:\Program Files\Bentley\ProjectWise\SDK\", "Machine")
    [Environment]::SetEnvironmentVariable("PWBinx64Dir", "C:\Program Files\Bentley\ProjectWise\bin\", "Machine")
    [Environment]::SetEnvironmentVariable("PWIncludeX64Dir", "C:\Program Files\Bentley\ProjectWise\SDK\include\", "Machine")
    [Environment]::SetEnvironmentVariable("PWLibx64Dir", "C:\Program Files\Bentley\ProjectWise\SDK\lib\x64\", "Machine")
    [Environment]::SetEnvironmentVariable("PWRsrcx64Dir", "C:\Program Files\Bentley\ProjectWise\rsrc\", "Machine")
    [Environment]::SetEnvironmentVariable("PWSDKx64Dir", "C:\Program Files\Bentley\ProjectWise\SDK\", "Machine")
    [Environment]::SetEnvironmentVariable("PythonDir", "C:\DevTools\Python27", "Machine")

    I posted these at this link: 

    Answer Verified By: Darius Simkunas