'How to call a mvsc dll (C++ or Rust) from Progress Open Edge
I have a dll that i want to call from Progress code but I can't complete.
I have tried with Visual Studio 2022, Windows C++ Dll and Rust Dll.
Windows C++, Visual Studio 2022 with Progress
Cpp
#include "pch.h"
#include <windows.h>
#include <string.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
//---------------------------------------------------------------------------
/*
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}
*/
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) int HelloWorld(int hello)
{
return hello * 2;
}
Progress
BLOCK-LEVEL ON ERROR UNDO, THROW.
PROCEDURE HelloWorld EXTERNAL "C:\Users\Steee\source\repos\DllHelloWorld\x64\Release\DllHelloWorld.dll" CDECL:
DEFINE INPUT PARAMETER hello AS SHORT NO-UNDO.
DEFINE OUTPUT PARAMETER rCode AS SHORT NO-UNDO.
END.
DEFINE VARIABLE hello AS INTEGER NO-UNDO.
DEFINE VARIABLE rCode AS INTEGER NO-UNDO.
hello = 3.
RUN HelloWorld(hello, OUTPUT rCode).
MESSAGE STRING(rCode)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
The code compiles without errors and warning but I've got "0" in MESSAGE STRING(rCode), this sould get "6".
Rust with mvsc with Progress
Rust lib.rs
use std::os::raw::{c_int};
#[no_mangle]
pub extern "C" fn HelloWorld(hello: c_int) -> c_int {
hello * 2
}
Rust Cargo.toml
[package]
name = "DllRust"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "dll_rust"
crate-type = ["cdylib"]
[dependencies]
C Header
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int HelloWorld(int hello);
Progress
BLOCK-LEVEL ON ERROR UNDO, THROW.
DEFINE VARIABLE iResult AS INTEGER NO-UNDO.
PROCEDURE HelloWorld EXTERNAL "C:\Users\Steee\CLionProjects\dll_rust\target\release\dll_rust.dll" CDECL:
DEFINE INPUT PARAMETER hello AS LONG.
DEFINE OUTPUT PARAMETER result AS LONG.
END.
RUN HelloWorld(3, OUTPUT iResult).
MESSAGE STRING(iResult)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
EDIT: The code compiles without errors and warning now but I've got "0" in MESSAGE STRING(iResult), this sould get "6".
Solution 1:[1]
Your define output parameter
needs to be a define return parameter
. See documentation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Stefan Drissen |