how to convert .so file as corresponding .dll in windows

Here you can find everything you need to know about Dll-Files. You can also share your knowledge regarding the topic.

Moderators: DllAdmin, DLLADMIN ONLY

Post Reply
sham

how to convert .so file as corresponding .dll in windows

Post by sham »

hai,
im working on linux .so files i want this .so file to be compatible with windows that is i want to convert linux .so file to corresponding .dll file , i have written the code in portable manner. here is my linux code
/*************pgm.h*****************/
__attribute__((dllexport)) double Mean(double,double);
__attribute__((dllexport)) void Display();

/**********pgm.c********************/
#include<stdio.h>
#ifdef __cplusplus

extern "C"
#endif
double Mean(double a,double b)
{
return (a+b)/2;
}

void Display()
{
printf("\nhai\n");
}

/***************pgmexe.c*******************/
#ifndef USE_PRECOMPILED_HEADERS

#ifdef WIN32
#include <direct.h>
#include <windows.h>

#else

#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <dlfcn.h>
#include "pgm.h"
#endif
//#include<iostream>
#endif

int main()
{
#ifdef WIN32
HINSTANCE lib_handle;
#else
void *lib_handl;
#endif

double (*func)(double,double);
void (*func1)();


#ifdef WIN32
lib_handle = LoadLibrary("libpgm.so");
if (!lib_handle)
{
printf("cannot able to load so library");
}
#else
lib_handl = dlopen("libpgm.so",RTLD_LAZY);
if (!lib_handl)
{
printf("cannot able to load so library");
}
#endif

#ifdef WIN32
func f1=(func)GetProcAddress(lib_handle,"Mean");
double d =f1(4.6,5.4);
printf("\nmean %f\n",d);

func1 f2=(func1)GetProcAddress(lib_handle,"Display");
f2();

#else
dlerror();
func =dlsym(lib_handl,"Mean");
const char* dlsym_error = dlerror();
if (dlsym_error)
{
printf("cant able to load mean");
}
double d =func(4.6,5.4);
printf("mean %f",d);

func1 =dlsym(lib_handl,"Display");
func1();
#endif

#ifdef WIN32
FreeLibrary(lib_handle);
#else
dlclose(lib_handl);
#endif
return 0;
}

finally i have created soname,realname,linker name as libpgm.so.1 libpgm.so.1.0 libpgm.so
now i have copied libpgm.so and renamed it as libpgm.dll and pasted in path of client program(i.e in windows) now im trying to execute it but im getting error as bad image check your installation diskette,but the same code as executed sucessfuly in linux, plz let me knw the solution
thanks....................................

Post Reply