-2

I want to know how can we call a function that is defined in external static class (dll file) without a call to it in main.

To make things clearer, consider an exe file of which code is not exposed and we cannot do any sort of modifications to it, now I want to test a exe file with certain test cases that are defined in my dll file for which a call to the function must me made within the main() function of the exe file. But as mentioned, I dont have permission to modify the code of exe file. Now how this dll function is invoked at the required pointof execution without a call to it using visual studio.

I want to call a function without adding any line to main function.

To make things clearer ,I just want to add some example

static class DllClass
{
   static void dllFunction()
   {
      //some implementation.
   }
}
class ThirdParty
{
  public static void Main()
  {
    //Default implementation that i cannot modify.
    //Invoking my static function at this point without calling.(i.e i cannot call DllClass.dllFunction()) 
    //continuing with default implementation.
  }
}     
GANESH GANI
  • 101
  • 11

1 Answers1

0

One idea is that using the Powershell call the dll file if you couldn't modify the code in the .exe.

For example, a simple library with methods.

namespace Math
{
public class Methods
{
public Methods()
{
}
public static int Compare1(int a, int b)
{
if (a return a;
else
return b;
}

public int Compare2(int a, int b)
{
if (a return a;
else
return b;
}
}
}

And then call it in the Powershell Environment:

[void][reflection.assembly]::LoadFile("C:/xxx.dll")
02.[Math.methods]::Compare1(10,8)
03.$a=New-Object Math.Methods
04.$a.Compare2(2,6)

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20