Jump to content


Check out our Community Blogs

g-man122

Member Since 28 Dec 2009
Offline Last Active Apr 16 2010 03:59 AM
-----

Posts I've Made

In Topic: [Help] Using/calling a function from a C++.DLL in C#.

16 April 2010 - 03:58 AM

Yes you can, you should have an header file and a source file. Header file contains the prototypes and the source file the definitions.


Could you correct my code, please ?

In Topic: [Help] Using/calling a function from a C++.DLL in C#.

15 April 2010 - 03:04 PM

#include "Windows.h"
#include <iostream>

extern "C"
{
    __declspec (dllexport) int SendMsg() { 
        return 101001;
    }

BOOL WINAPI DllMain (HMODULE hModule, DWORD state, LPVOID lpReserved)    {
    if (state == DLL_PROCESS_ATTACH)    {
        MessageBoxA(NULL,"Hi","Hi",MB_OK);
        CreateThread (0,0,(LPTHREAD_START_ROUTINE)SendMsg,0,0,0);
    }
    return TRUE;
}
}

Like that ?
And I wouldn't be able to add the DllMain part at the top of the file, it won't let me declare new functions.

Thanks for your help, anyhow.

In Topic: C++ prog compilation problem

15 April 2010 - 02:57 PM

oh yes, and to just use cout, add using namespace std; or else you are going to have to add it to all your cout statements
Let me try again with a code example... ^_^
this is the better way

#include <iostream>

using namespace std;

int main()
{
    cout<<"Hello world"<<endl;
}
this is the annoying way (at least to me)
#include <iostream>

int main()
{
    std::cout<<"Hello world"<<std::endl;
}


Just to clarify, you would use std::cout; because there's no point in importing the whole std namespace, especially if you're only going to be using cout. Optionally - to save typing "std::" at the start of each of your cout's - you could add "using std::cout;" under includes, it'll just "tell" your compiler you're only going to be using cout from the std namespace.
It's no big deal, it'll just save you from importing the whole namespace, hence making your file bigger in size.
Just remember to add the "using std::partofnamespace" for each function from the std namespace you're going to be using.

Hope this helped :].

In Topic: [Help] Using/calling a function from a C++.DLL in C#.

15 April 2010 - 02:50 PM

what compiler are you using to build the DLL?

Microsoft's one. (from Visual C++ 2008)

In Topic: [Help] Using/calling a function from a C++.DLL in C#.

15 April 2010 - 02:22 PM

read this also

dllexport, dllimport


Yeah, I just remembered that.

I think I may be getting somewhere, though I'm getting the same error.
This is my code :
#922173 - Pastie
Maybe there's something I'm not seeing ?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download