Witam
Tworzę funkcję do serwera PostgreSQL w czystym C. Piszę to w Borlandzie Builderze jako projekt dll.
Funkcja ma zmniejszać obrazki z bazy danych
Po licznych bojach zdołałem wyeliminować wszystkie błędy podczas kompilowania.
Jednak pojawiają się 3 błędy linkera :
" [Linker Error] Unresolved external '_pgwin32_fopen' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\RESIZEDLLTEST\UNIT1.OBJ
[Linker Error] Unresolved external '_CurrentMemoryContext' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\RESIZEDLLTEST\UNIT1.OBJ
[Linker Error] Unresolved external '_MemoryContextAlloc' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\PROJECTS\RESIZEDLLTEST\UNIT1.OBJ
"
Widzę deklaracje tych funkcji w pliku Postgresa - palloc.h, ale nie mogę znaleźć definicji.
Oto mój kod :
#include<stdio.h>
#include<stdlib.h>
#include <basetsd.h>
#include "postgres.h"
#include <windows.h>
#include<locale.h>
#include<setjmp>
#include"jpeglib.h"
#include "jerror.h"
#include "fmgr.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
#pragma hdrstop
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
extern bytea* __declspec(dllexport) kompresuj(bytea* zdjwej,int zdjwyj_sz, int zdjwyj_w,int stkompr, bool domyslne,J_DCT_METHOD metodadctbmp,int wspskalibmp, boolean blokwygl, J_COLOR_SPACE tabkolorbmp, boolean kwantkolorbmp,int wymilosckolbmp,boolean drprzebkwantbmp,J_DITHER_MODE metodawyglbmp, J_COLOR_SPACE tabkolor,J_DCT_METHOD metodadctjpg,int wygladzjpg,int wspskalijak, boolean niskajak);
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
struct my_error_mgr {
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
typedef struct my_error_mgr *my_error_ptr;
void my_error_exit(j_common_ptr cinfo)
{
my_error_ptr myerr = (my_error_ptr) cinfo->err;
(*cinfo->err->output_message) (cinfo);
longjmp(myerr->setjmp_buffer, 1);
}
int czytajwymiarywej(char *filename,int wymiary[])
{ struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE *infile;
if ((infile = fopen(filename, "rb")) == NULL) {
return -1;
}
jerr.pub.error_exit = my_error_exit;
cinfo.err = jpeg_std_error(&jerr.pub);
jpeg_CreateDecompress(&cinfo,JPEG_LIB_VERSION,(size_t)sizeof(cinfo));
if (setjmp(jerr.setjmp_buffer)) {
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return -2;
}
jpeg_stdio_src(&cinfo, infile);
(void) jpeg_read_header(&cinfo, TRUE);
wymiary[0] = cinfo.image_width;
wymiary[1] = cinfo.image_height;
jpeg_destroy_decompress(&cinfo);
return 0;
}
int read_jpeg(j_decompress_ptr cinfoptr, unsigned char **image_buffer,int *image_width, int *image_height)
{ JSAMPARRAY jpeg_buffer;
long int i_buffer, i_image;
(void) jpeg_start_decompress(cinfoptr);
*image_buffer = (unsigned char *) malloc(*image_width * *image_height * (cinfoptr).out_color_components sizeof(unsigned char));
if (image_buffer == NULL) {
(void) jpeg_finish_decompress(cinfoptr);
jpeg_destroy_decompress(cinfoptr);
return -3;
}
jpeg_buffer = ((*cinfoptr).mem->alloc_sarray)((j_common_ptr) cinfoptr, JPOOL_IMAGE,(*cinfoptr).output_width * (*cinfoptr).output_components, 1);
i_image = 0;
while ((*cinfoptr).output_scanline < (*cinfoptr).output_height) {
(void) jpeg_read_scanlines(cinfoptr, jpeg_buffer, 1);
if ((*cinfoptr).output_components == 3) {
for (i_buffer = 0; (unsigned)i_buffer < (*cinfoptr).output_width * (*cinfoptr).output_components; i_buffer++, i_image++)
(*image_buffer)[i_image] = jpeg_buffer[0][i_buffer];
}
}
(void) jpeg_finish_decompress(cinfoptr);
jpeg_destroy_decompress(cinfoptr);
return 0;
}
int write_jpeg(j_compress_ptr cinfoptr, unsigned char *image_buffer,int quality, int image_width, int image_height)
{ JSAMPROW row_pointer[1];
if (quality < 0) quality = 0; else if(quality > 100) quality = 100;
(*cinfoptr).image_width = image_width;
(*cinfoptr).image_height = image_height;
jpeg_set_quality(cinfoptr, quality, FALSE);
jpeg_start_compress(cinfoptr, TRUE);
while ((*cinfoptr).next_scanline < (*cinfoptr).image_height) {
row_pointer[0] = &image_buffer[(cinfoptr).next_scanline image_width * (*cinfoptr).input_components];
(void) jpeg_write_scanlines(cinfoptr, row_pointer, 1);
}
jpeg_finish_compress(cinfoptr);
jpeg_destroy_compress(cinfoptr);
return 0;
}
bytea* kompresuj(bytea* zdjwej,int zdjwyj_sz, int zdjwyj_w,int stkompr, bool domyslne,J_DCT_METHOD metodadctbmp,int wspskalibmp, boolean blokwygl, J_COLOR_SPACE tabkolorbmp, boolean kwantkolorbmp,int wymilosckolbmp,boolean drprzebkwantbmp,J_DITHER_MODE metodawyglbmp, J_COLOR_SPACE tabkolor,J_DCT_METHOD metodadctjpg,int wygladzjpg,int wspskalijak, boolean niskajak)
{
int rc;unsigned char* zdjwyj;
int zdjwej_w, zdjwej_sz;
int jakosc,i, j, k, ib, jb; double ratio;
int wymiary[2];
bytea* zdjwyjwyn;
/* Dekompresja - ustawianie obiektu cinfo /
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
/ Kompresja dane do kompresji /
struct jpeg_compress_struct cinfokompr;
struct my_error_mgr jerr1;
/ ------------------------/
jerr.pub.error_exit = my_error_exit;
cinfo.err = jpeg_std_error(&jerr.pub);
jpeg_CreateDecompress(&cinfo,JPEG_LIB_VERSION,(size_t)sizeof(cinfo));
if (setjmp(jerr.setjmp_buffer)) {
jpeg_destroy_decompress(&cinfo);
};
jpeg_stdio_src(&cinfo, (FILE) (unsigned)zdjwej->vl_dat);
(void) jpeg_read_header(&cinfo, TRUE);
if(!domyslne)
{
cinfo.dct_method = metodadctbmp;
cinfo.scale_denom = wspskalibmp;
cinfo.do_block_smoothing = blokwygl;
cinfo.out_color_space = tabkolorbmp;
cinfo.quantize_colors = kwantkolorbmp;
cinfo.desired_number_of_colors = wymilosckolbmp;
cinfo.two_pass_quantize = drprzebkwantbmp;
cinfo.dither_mode = metodawyglbmp;
}
else
{
cinfo.dct_method = JDCT_FLOAT;
}
if (zdjwej_sz > zdjwej_w)
{
ratio = zdjwyj_sz / (double)zdjwej_sz;
zdjwyj_w = (int)((double)zdjwej_w * ratio);
}
else
{
ratio = zdjwyj_w / (double)zdjwej_w;
zdjwyj_sz = (int)((double)zdjwej_sz * ratio);
}
rc = read_jpeg(&cinfo, &zdjwyj ,&zdjwyj_sz, &zdjwyj_w);
if (rc != 0) {}
else
{
free(zdjwej);
#ifdef Zmniejszanie
zdjwej1 = (unsigned char *) malloc(zdjwyj_sz * zdjwyj_w *cinfo.input_components * sizeof(unsigned char));
for (j = 0; j < zdjwyj_w; j++)
{
jb = (int)((double)j / ratio);
for (i = 0; i < zdjwyj_sz; i++)
{
ib = (int)((double)i / ratio);
for (k = 0; k < 3; k++) zdjwyj[(j * zdjwyj_sz + i) * 3 + k]= zdjwej[(jb * zdjwej_sz + ib) * 3 + k];
}
}
#endif
jerr1.pub.error_exit = my_error_exit;
cinfokompr.err = jpeg_std_error(&jerr1.pub);
jpeg_create_compress(&cinfokompr);
zdjwyjwyn = (bytea*) palloc(sizeof(bytea));
jpeg_stdio_dest(&cinfokompr, (FILE*)(unsigned) zdjwyjwyn->vl_dat);
if(!domyslne)
{
cinfokompr.dct_method = metodadctjpg;
jpeg_set_linear_quality(&cinfokompr, wspskalijak,niskajak);
cinfokompr.jpeg_color_space = tabkolor;
cinfokompr.smoothing_factor = wygladzjpg;
}
else
{
jpeg_set_defaults(&cinfokompr);
cinfokompr.dct_method = JDCT_FLOAT;
cinfokompr.smoothing_factor = 20;
}
rc = write_jpeg(&cinfokompr,zdjwyj,stkompr,zdjwyj_sz, zdjwyj_w);
if (rc!= 0) return NULL;
return zdjwyjwyn;
}
return NULL;
}
"
Z góry dziękuję za pomoc