Lists: | pgsql-hackers |
---|
From: | Przemek Lisowski <przemek(at)lisnet(dot)info> |
---|---|
To: | <pgsql-hackers(at)postgresql(dot)org> |
Subject: | C-function, don't load external dll file |
Date: | 2012-11-20 14:07:53 |
Message-ID: | c2742b8c486bda93bbab4fe098bd182e@lisnet.info |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
I write my dll files in visual studio 2010.
The dll file (name
fservice.dll), which has an external function, code write in c++
(VS2010, I have dll and lib files)
char * convert(char *)
I tested my
fservice.dll in console application which called function in this dll.
It was work fine. I have a problem when a write and tests in Postgrsql.
Dll file witch has c-function, who exports and imports to postgresql:
#include "postgres.h"
#include "fmgr.h"
#include <windows.h>
#include
<stdio.h>
typedef char* (__cdecl *MYPROC)(char * value);
__declspec(
dllexport ) PG_FUNCTION_INFO_V1(transform);
__declspec( dllexport )
Datum transform (PG_FUNCTION_ARGS)
{
HINSTANCE hinstLib=
LoadLibrary("fservice.dll");
char * pointer; text *t =
PG_GETARG_TEXT_P(0);
if (hinstLib != NULL)
{
ProcAdd = (MYPROC)
GetProcAddress(hinstLib, "convert");
pointer=ProcAdd("text");
FreeLibrary(hinstLib);
}
else
PG_RETRUN_NULL();
/* * code */
PG_RETURN_TEXT_P(new_t);
}
I have a problem because, mod is doesn't
exists. Path to dll file I check before write. Compile this c-function,
and when i debug i saw it HINSTANCE hinstLib it wasn't created. It
wasn't NULL or any value, It wasn't exist. Finally my c-function doesn't
use my function form external dll.
HOW LOAD DLL AND USE MY EXTERNAL
FUNCTION ?
My external function form dll and LoadLibrary() is not
called by dll program with called by Postgresql, Why?
Przemek
1 down
vote favorite [1]
1
I write my dll files in visual studio 2010.
The
dll file (name fservice.dll), which has an external function, code write
in c++ (VS2010, I have dll and lib files)
char * convert(char *)
Dll
file witch has c-function, who exports and imports to postgresql:
typedef char* (__cdecl *MYPROC)(char * value);
PG_FUNCTION_INFO_V1(transform); Datum transform (PG_FUNCTION_ARGS) {
HINSTANCE hinstLib= LoadLibrary("fservice.dll"); char * pointer; text *t
= PG_GETARG_TEXT_P(0); if (hinstLib != NULL) { ProcAdd = (MYPROC)
GetProcAddress(hinstLib, "convert"); pointer=ProcAdd("text");
FreeLibrary(hinstLib); } /* * code */ PG_RETURN_TEXT_P(new_t); }
I have
a problem because, mod is doesn't exists. Path to dll file I check
before write. Compile this c-function, and when i debug i saw it
HINSTANCE hinstLib it wasn't created. It wasn't NULL or any value, It
wasn't exist. Finally my c-function doesn't use my function form
external dll.
HOW LOAD DLL AND USE MY EXTERNAL FUNCTION ?
My
external function form dll and LoadLibrary() is not called by dll
program with called by Postgresql, Why?
Links:
------
[1]
http://stackoverflow.com/questions/13469028/postgresql-c-function-dont-load-external-dll-file#
From: | Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr> |
---|---|
To: | Przemek Lisowski <przemek(at)lisnet(dot)info> |
Cc: | <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: C-function, don't load external dll file |
Date: | 2012-11-21 14:58:11 |
Message-ID: | m2r4nnngu4.fsf@2ndQuadrant.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
Przemek Lisowski <przemek(at)lisnet(dot)info> writes:
> HOW LOAD DLL AND USE MY EXTERNAL
> FUNCTION ?
You need to declare it in SQL, maybe like this:
create function public.transform(text) returns text
as '$libdir/fservice', 'transform' language C;
See also the LOAD command and the CREATE EXTENSION documentation for how
to organise testing and shipping of your code.
Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support
From: | pl65 <przemek(at)lisnet(dot)info> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: C-function, don't load external dll file |
Date: | 2012-11-22 09:26:29 |
Message-ID: | 1353576388905-5733197.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Dimitri Fontaine-7 wrote
> You need to declare it in SQL, maybe like this: create function
> public.transform(text) returns text as '$libdir/fservice', 'transform'
> language C;
*I'm afraid that I won't do it becouse fservice.dll is writen in c++, but
dll file which contains function transform (this function export to
Postgresql) was wrote in ANSI C. *Secondly, LOAD function in posttgresql
libraries that are use of my all dependent dll? I think i should use:LOAD
'fservice.dll' But I don't know which dll load to use function or makros
which called from windows.h (HINSTANCE, LoadLibray(), GetProcAddress())?
--
View this message in context: http://postgresql.1045698.n5.nabble.com/C-function-don-t-load-external-dll-file-tp5732931p5733197.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.