Hello All,
I am developping a script to do some activity on all the projects inside the ProjectWise with using the SDK (C++). The plan is to generate a DLL file and import in Powershell to get input as a parameter. Below are the code that i am using in the C++ environment. But some issues that i cannot suceed to load in powershell. It would be great if someone correct me what i have done a wrong. I cannot put my detailed function here, but i placed the main function here.
C++
#include "pch.h" #include <iostream> #include <string> #include <Windows.h> namespace MyNamespace { class MyDLLClass { public: static void InputData(const char* var1, const char* var2, const char* var3) { std::cout << "Received data in InputData function:" << std::endl; std::cout << "Variable 1: " << var1 << std::endl; std::cout << "Variable 2: " << var2 << std::endl; std::cout << "Variable 3: " << var3 << std::endl; } }; } // Entry point function for the DLL extern "C" __declspec(dllexport) void RunDLL() { std::cout << "DLL is running..." << std::endl; } int main() { std::cout << "Starting process!\n"; aaApi_Initialize(AAMODULE_EXPLORER); SetShellInput MainInput; LPCWSTR lDatasource = 'XXXXX'; LPCWSTR projectName = 'XXXX'; LPCWSTR uniqueID = 'XXXX'; LPCWSTR usrlistName = 'XXXXX'; bool loginSuccess = loginDatasource(lDatasource); if (loginSuccess == true) { std::cout << "SUCCESS!\n"; } else { long errorID = aaApi_GetLastErrorId(); std::cout << "FAILURE!\n"; } long projectID = getProjectID(projectName); if (projectID > 0) { LONG viewerUserListID = getUserlistIDBySQL(usrlistName); makeProjectReadOnly(projectID, uniqueID, viewerUserListID); } aaApi_Uninitialize(); }
PowerShell
# Load the DLL $dllPath = "C:\Temp\DLL\DLLPSImport.dll" Add-Type -TypeDefinition @" namespace MyNamespace { public class MyDLLClass { public static void ProcessData(string var1, string var2, string var3) { [System.Console]::WriteLine("Received data in ProcessData function:") [System.Console]::WriteLine("Variable 1: " + var1) [System.Console]::WriteLine("Variable 2: " + var2) [System.Console]::WriteLine("Variable 3: " + var3) # Perform processing here # You can access var1, var2, and var3 in your processing logic } } } "@ Add-Type -Path $dllPath -Verbose # Define your data variables $variable1 = "Data1" $variable2 = "Data2" $variable3 = "Data3" # Call the ProcessData function in the DLL with your data [MyNamespace.MyDLLClass]::ProcessData($variable1, $variable2, $variable3)
Yes, I am aware, we have all PS cmdlets, but the process I am doing is very long and it taking more time to complete it.