www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to get normal DLL method name

reply "Denis Mezhov" <d.o.mezhov gmail.com> writes:
DLL

module dllmain;

import std.c.windows.windows;
import core.sys.windows.dll;
import core.stdc.stdio;

__gshared HINSTANCE g_hInst;

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID 
pvReserved)
{
     final switch (ulReason)
     {
     case DLL_PROCESS_ATTACH:
         g_hInst = hInstance;
         dll_process_attach( hInstance, true );
         break;

     case DLL_PROCESS_DETACH:
         dll_process_detach( hInstance, true );
         break;

     case DLL_THREAD_ATTACH:
         dll_thread_attach( true, true );
         break;

     case DLL_THREAD_DETACH:
         dll_thread_detach( true, true );
         break;
     }
     return true;
}

export void dllprint()
{
	printf("hello dll world\n");	
}

In Main

FARPROC fp = GetProcAddress(h, "dllmain");  // Not work
if fp is null)
{
    printf("error loading symbol()\n");
}


FARPROC fp = GetProcAddress(h, "D7dllmain8dllprintFZv"); // It 
work
if fp is null)
{
    printf("error loading symbol()\n");
}

How i set/get normal name in DLL?
Feb 15 2014
parent reply "Denis Mezhov" <d.o.mezhov gmail.com> writes:
Sorry

// Not work
FARPROC fp = GetProcAddress(h, "dllprint");
if fp is null)
{
     printf("error loading symbol()\n");
}

// It work
FARPROC fp = GetProcAddress(h, "D7dllmain8dllprintFZv");

if fp is null)
{
     printf("error loading symbol()\n");
}
Feb 15 2014
parent reply "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Sunday, 16 February 2014 at 00:46:13 UTC, Denis Mezhov wrote:
 Sorry

 // Not work
 FARPROC fp = GetProcAddress(h, "dllprint");
 if fp is null)
 {
     printf("error loading symbol()\n");
 }

 // It work
 FARPROC fp = GetProcAddress(h, "D7dllmain8dllprintFZv");

 if fp is null)
 {
     printf("error loading symbol()\n");
 }
How about this: // in dll: extern(C) void dllprint() { /* ... */ } // in main: auto fp = GetProcAddress(h, "dllprint"); ?
Feb 15 2014
parent reply "Denis Mezhov" <d.o.mezhov gmail.com> writes:
Don't work

DLL

module dllmain;

import std.c.windows.windows;
import core.sys.windows.dll;
import core.stdc.stdio;

__gshared HINSTANCE g_hInst;

export void dllprint()
{
	printf("hello dll world\n");	
}

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID 
pvReserved)
{
     final switch (ulReason)
     {
     case DLL_PROCESS_ATTACH:
         g_hInst = hInstance;
         dll_process_attach( hInstance, true );
         break;

     case DLL_PROCESS_DETACH:
         dll_process_detach( hInstance, true );
         break;

     case DLL_THREAD_ATTACH:
         dll_thread_attach( true, true );
         break;

     case DLL_THREAD_DETACH:
         dll_thread_detach( true, true );
         break;
     }
     return true;
}




Main

import core.runtime;

import std.stdio;
import std.container;
import std.range;
import std.c.windows.windows;

alias void function() aaa;
aaa bbb;

extern (Windows)
void main(string[] args)
{
    HMODULE h;
    FARPROC fp;	
    h = cast(HMODULE) Runtime.loadLibrary("DynamicLib1.dll");	
    if (h is null)
       {
          printf("error loading mydll.dll\n");
       }
    fp = GetProcAddress(h, "dllprint");  //Don't work
       if (fp is null)
       {
           printf("error loading symbol()\n");
       }

   bbb = cast(aaa)fp;
   bbb();

   readln();
}
Feb 15 2014
parent reply "Denis Mezhov" <d.o.mezhov gmail.com> writes:
On Sunday, 16 February 2014 at 07:17:48 UTC, Denis Mezhov wrote:
 Don't work

 DLL

 module dllmain;

 import std.c.windows.windows;
 import core.sys.windows.dll;
 import core.stdc.stdio;

 __gshared HINSTANCE g_hInst;

 export void dllprint()
 {
 	printf("hello dll world\n");	
 }

 extern (Windows)
 BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID 
 pvReserved)
 {
     final switch (ulReason)
     {
     case DLL_PROCESS_ATTACH:
         g_hInst = hInstance;
         dll_process_attach( hInstance, true );
         break;

     case DLL_PROCESS_DETACH:
         dll_process_detach( hInstance, true );
         break;

     case DLL_THREAD_ATTACH:
         dll_thread_attach( true, true );
         break;

     case DLL_THREAD_DETACH:
         dll_thread_detach( true, true );
         break;
     }
     return true;
 }




 Main

 import core.runtime;

 import std.stdio;
 import std.container;
 import std.range;
 import std.c.windows.windows;

 alias void function() aaa;
 aaa bbb;

 extern (Windows)
 void main(string[] args)
 {
    HMODULE h;
    FARPROC fp;	
    h = cast(HMODULE) Runtime.loadLibrary("DynamicLib1.dll");	
    if (h is null)
       {
          printf("error loading mydll.dll\n");
       }
    fp = GetProcAddress(h, "dllprint");  //Don't work
       if (fp is null)
       {
           printf("error loading symbol()\n");
       }

   bbb = cast(aaa)fp;
   bbb();

   readln();
 }
Oh, sorry export extern (C) void dllprint() { printf("hello dll world\n"); } It work
Feb 15 2014
parent Mike Parker <aldacron gmail.com> writes:
On 2/16/2014 4:20 PM, Denis Mezhov wrote:
 On Sunday, 16 February 2014 at 07:17:48 UTC, Denis Mezhov wrote:
 extern (Windows)
 void main(string[] args)
 {
    HMODULE h;
I'm curious why you're declaring your main method as extern(Windows).
Feb 16 2014