Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winim/clr parameter passing for non-main methods #86

Open
S3cur3Th1sSh1t opened this issue Jun 14, 2022 · 2 comments
Open

winim/clr parameter passing for non-main methods #86

S3cur3Th1sSh1t opened this issue Jun 14, 2022 · 2 comments

Comments

@S3cur3Th1sSh1t
Copy link

Hey,

I'm facing a problem similar to this one. I would like to load a DLL from Nim passing parameters to it's constructor. The C# example is the following:

namespace TestSpace
{
    public class Run
    {
        public Run(uint value1, IntPtr value2, int value3)
        {
             // Set Stuff
        }

        public void DoStuff()
        {
             // Do Stuff
        }
    }
}

I tried executing this constructor via e.g.

var assembly = load(dllbytes)
var Test = assembly.GetType("TestSpace.Run")
dump Test
# Works fine till there

with the following trials:

var
    intvalue1: int = 1
    intvalue2: int = 2
    testHandle: HANDLE
Test.new(intvalue1,intvalue2,testHandle)
# leads to Error: unhandled exception: unable to invoke specified member: new (0x80131512) [CLRError]
Test.new(nil, aaa,testHandle,aaa)
# leads to unable to invoke specified member: CreateInstance (0x80131604) [CLRError]
var cmd: seq[string]
var i = 1
while i <= paramCount():
    cmd.add(paramStr(i))
    inc(i)
echo cmd
var arr = toCLRVariant(cmd, VT_BSTR)
Test.invoke(nil, toCLRVariant([arr]))
# Also Error: unhandled exception: unable to invoke specified member: CreateInstance (0x80131604) [CLRError]
# This is a string array from how I understood it, actually makes no sense as the function expects uint, Pointer and int. But it's not possible to embed (uint,HANDLE,int) in an array right?

I also tried executing the DoStuff function via e.g.

Test.invoke("DoStuff", BindingFlags_InvokeMethod or BindingFlags_Default)
# failed with Error: unhandled exception: unable to invoke specified member: DoStuff (0x80131512)
Test.DoStuff()
# same error
var arr = toCLRVariant([""], VT_BSTR) # Passing no arguments
echo @asd.DoStuff(nil, toCLRVariant([arr]))
# Error: unhandled exception: convert from VT_ARRAY(1D)|VT_VARIANT to integer [VariantConversionError]
# Why does it expect integer input?

Some idea how to pass the parameters for these examples?
Appreciate any help.

Greetings

@daddycocoaman
Copy link

@S3cur3Th1sSh1t Did you ever figure this out? I'm having similar issues trying to create Assembly/AppDomain event handlers and basically getting the same errors.

@S3cur3Th1sSh1t
Copy link
Author

No, as a Workaround I was using an executable instead of an DLL and loaded that as parameter passing works fine there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants