Hackhers

C++ Dll __stdcall problem

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



witch compiler do you use?

 

Saludos


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

witch compiler do you use?

 

Saludos

I use Visual Studio 2015 but Platform toolset is Visual Studio 2010

Share this post


Link to post
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


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
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


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

 

Saludos


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The most usual way is to add definition file (again usually called "Exports.def"). Google a bit, it's been beaten to death many times before. Super simple.

Edited by trancexx
eng.

♡♡♡

.

eMyvnE

Share this post


Link to post
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