How to call program written in c++ call my DLL written in c -


i have developped dll in c , have called in c++ program method

#include <cstdlib> #include <iostream> #include <windows.h>  #ifdef __cplusplus extern "c" { #endif #include "mydll.h" #ifdef __cplusplus } #endif using namespace std;  int main(int argc, char *argv[]) {     struct myown_struct *ss = null;     int = 0,j = 0, result = 0;     struct myown_struct2 *s = null;     myfunction("string1", "string2", "string3", 1500);     system("pause");     return exit_success; } 

mydll.h :

#ifndef _dll_h_ #define _dll_h_  #if building_dll # define dllimport __declspec (dllexport) #else /* not building_dll */ # define dllimport __declspec (dllimport) #endif /* not building_dll */  struct myown_struct {   int fd;   char buf[32];   unsigned int len; } __attribute__((packed));  dllimport void myfunction(char *s1, char* s2, char *s3, int n);  #endif /* _dll_h_ */ 

i error :

c:\users\user01\desktop\test\main.cpp in function int main(int, char**) c:\users\user01\desktop\test\main.cpp myfunction' undeclared (first use function)

how can fix it?

your header file mydll.h appears missing declaration of myfunction. correct omission , code compile.

on top of need ensure that:

  • the .lib import library created when compiled dll passed linker when link c++ program.
  • the dll can found when attempt run program. best achieved placing dll in same directory executable.

i comment expect see extern "c" in header file rather forcing every single user of header file write extern "c". header file should stand alone.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -