Jump to content

C++ Dll __stdcall problem


Hackhers
 Share

Recommended Posts

Hey there, Since DllCall is using stdcall as I see in forums I'm trying to change cdecl to stdcall but It still not working. Any ideas ?

Auto IT code:

$serverLib = DllOpen(@ScriptDir & "/TestServer.dll")
$result = DllCall($serverLib, "str", "ultraDil", "str", "TR")
DllClose($serverLib)

 

C++ Code:

#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <string.h>

#define EOF (-1)
#define debug true


std::wstring s2ws(const std::string& s)
{
    int len;
    int slength = (int)s.length() + 1;
    len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
    wchar_t* buf = new wchar_t[len];
    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
    std::wstring r(buf);
    delete[] buf;
    return r;
}


char diller[6][3] = { "TR", "NE", "DE", "FR", "IT", "ES" };

char TRyazi[10][32] = {
    { "Bele" },
    { "sla" },
    { "rdu" },
    { "Buyu" },
    { "klan" },
    { "" },
    { "" },
    { "" },
    { "" },
    { "" }
};


TCHAR fileName[MAX_PATH + 1];



#ifdef __cplusplus    // If used by C++ code, 
extern "C" {          // we need to export the C interface
#endif

    __declspec(dllexport) char* __stdcall ultraDil(char* a)
    {
        
        std::string dil(a);
        std::string dondur("");
        std::string ekle("|");
        int i = 0;
        for (i = 0; i < 10; i++)
        {
            if (dil.compare("TR") == 0)
            {
                dondur += TRyazi[i];
            }
            dondur += ekle;
        }
        char * cstr = new char[dondur.length() + 1];
        std::strcpy(cstr, dondur.c_str());

        return cstr;
    }

#ifdef __cplusplus
}
#endif

 

Edited by Hackhers
Link to comment
Share on other sites

Link to comment
Share on other sites

This work for me.

$serverLib = DllOpen(@ScriptDir & "/testserver.dll")
$result = DllCall($serverLib, "str", "_ultraDil@4", "str", "TR")
MsgBox(0,"",$result[0])
DllClose($serverLib)

Saludos

Link to comment
Share on other sites

Did you mean this:

 __declspec(dllexport) char* __cdecl ultraDil(char* a)

the call look like this:

$serverLib = DllOpen(@ScriptDir & "/prueba.dll")
$result = DllCall($serverLib, "str:cdecl", "ultraDil", "str", "TR")
MsgBox(0,"",$result[0])
DllClose($serverLib)

Saludos

Link to comment
Share on other sites

This work for me.

$serverLib = DllOpen(@ScriptDir & "/testserver.dll")
$result = DllCall($serverLib, "str", "_ultraDil@4", "str", "TR")
MsgBox(0,"",$result[0])
DllClose($serverLib)

Saludos

Yep thanks, Part that I don't know is why we use @4 at "_ultraDil@4" part,

And Is there any way to use it like that by changing the c++ code:

$serverLib = DllOpen(@ScriptDir & "/testserver.dll")
$result = DllCall($serverLib, "str", "ultraDil", "str", "TR")
MsgBox(0,"",$result[0])
DllClose($serverLib)

 

Edited by Hackhers
Link to comment
Share on other sites

Search for C++ DLL Export: Decorated/Mangled names I really never care about funtion name.

 

Saludos

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...