Shoutbox

My Own C++ dll - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: My Own C++ dll (/showthread.php?tid=90502)

My Own C++ dll by TheSte on 05-04-2009 at 05:49 PM

Hi all...I know there are a lot of similar threads but I haven't understood this yet...

This is the code in dllmain.cpp

code:
#include "stdafx.h"
extern "C"__declspec(dllexport) int somma(int a, int b);
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

int somma(int a, int b){

    return a + b;

}

the building is ok...but when I load it with plus it says:

"Bad calling convention detected for "somma" in "C:\Program Files\Messenger Plus! Live\Scripts\nomi\dll.dll". The function must be declared with __stdcall and called with the appropriate number of parameter."

How I can declare it with __stdcall ?




sorry this is the js code

code:
function OnEvent_Initialize(MessengerStart)
{
var s=0;

s= Interop.Call(MsgPlus.ScriptFilesPath + "\\dll.dll", "somma", "2","3");
MsgPlus.DisplayToast("sss", s);
Interop.FreeDll(MsgPlus.ScriptFilesPath + "\\dll.dll");
}

RE: My Own C++ dll by mezzanine on 05-04-2009 at 06:04 PM

code:
extern "C" __declspec(dllexport) int __stdcall somma(int a, int b) {
    return a + b;
}


RE: My Own C++ dll by TheSte on 05-04-2009 at 06:31 PM

Thank u :)

But now t says that it fails the collocation of the function "somma"...O.o


edit: mmm..it seems to not find the somma function....the name is correct..so why?


SOLVED

With the help of http://www.dependencywalker.com/ I've found the real name of funvtion that was _somma@8


RE: My Own C++ dll by TheSteve on 05-07-2009 at 01:11 AM

If you remove the __declspec(dllexport) then use a .def file, the name will remain in a readable format.


RE: My Own C++ dll by TheSte on 05-10-2009 at 02:07 PM

how can I create a .def?


RE: My Own C++ dll by segosa on 05-10-2009 at 08:05 PM

...

Project -> Add New -> .def


RE: My Own C++ dll by TheSteve on 05-11-2009 at 05:16 AM

Right. For VC6, you just create a new text file and save it as <projectname>.def

The contents of the file can look something like this:

code:
LIBRARY "My Library"
EXPORTS
    ; Explicit Exports go here
    MyFunction

RE: My Own C++ dll by TheSte on 05-11-2009 at 12:19 PM

ok thanks a lot ; )