-1

I am making a computer app in C++/CLR and I just hit the wall. I'm loading the dll using the loadlibrary function and I am able to call the functions too but when I try to send a parameter for example if my function is:

std::string msgbox(std::string str)
{
    MessageBoxA (0,str.c_str(),"TiTle", MB_OK | MB_ICONINFORMATION);
    return str;
}

In a native c++ app when I call the function after loadlibrary and getprocaddress

std:: tmp = msg ("String");

tmp becomes "String"; and I see a Message box with String as the message but if I use C++/CLR I get like some rubbish while printing the message content in the message box if I pass in a parameter and the tmp variable would contain some trash text too how can I just load it the same way as I am doing but without this trash in the way

This is the output and the source code too:
Source: https://uploadfiles.io/itm93
Error images: https://imgur.com/a/WM7MK4c

user71381
  • 33
  • 6
  • we'd need a [mcve] to tell whats going wrong. your second snippet won't compile and doesn't use the same function name as your first snippet – Alan Birtles Aug 19 '18 at 19:21
  • @AlanBirtles what u mean like an example ? – user71381 Aug 19 '18 at 19:42
  • Something that people can put in a compiler and reproduce the problem, did you read [mcve]? – Alan Birtles Aug 19 '18 at 20:22
  • @AlanBirtles okay I have added a sample source working with just native c++ and with c++/clr to see the error u can see from the image link the errors I am encountering and thank you – user71381 Aug 20 '18 at 12:23

1 Answers1

0

It looks like you are compiling your c++ dlls with gcc. You can't pass standard library types between DLLs/applications compiled against different standard libraries.

You either need to compile everything with visual studio (and the same runtime library, you can't mix debug/release or the static/shared runtimes) or only pass raw character pointers over dll boundaries.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • So if i run visual studio copy pasted the dll code into it and compiled it with native c++ release and then loaded it into c++/clr will it work ? My target here is that you can easily extract the source code of a c++/clr app and if i made some of my functions inside dlls i can make it a little bit harder to crack – user71381 Aug 20 '18 at 13:12
  • @user71381 yes if its all compiled with visual studio it should work. You shouldn't need a separate dll to obfuscate your code though, as far as I know pure native c++ parts of a c++/clr library aren't decompilable – Alan Birtles Aug 20 '18 at 13:15
  • see https://stackoverflow.com/questions/17913270/could-c-net-assemblies-be-decompiled-easily – Alan Birtles Aug 20 '18 at 13:16
  • Dude i will try it thanks first of sll you just made my day, and second i want to integrate things into my project like anti tampering and anti reverse engineering into the exe and the dll this way when the exe is patched the dll will search for where it is being called and delete the program and ask the user to force reinstall it but there a way to obfuscate clr ? More a second way then just using a packer – user71381 Aug 20 '18 at 13:18
  • I assume the normal .net obfuscators will work with the IL parts of your c++/clr code, the non clr parts will be as hard/easy to decompile as any other c++ application. – Alan Birtles Aug 20 '18 at 13:20
  • Thanks for making my day dude i will try it rn – user71381 Aug 20 '18 at 13:22