DLL file question

This is a discussion on DLL file question within the C Programming forums, part of the General Programming Boards category; I am trying to write DLL files under the Digital Mars C/C++ compiler for use with Liberty BASIC, but I ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    Unhappy DLL file question

    I am trying to write DLL files under the Digital Mars C/C++ compiler for use with Liberty BASIC, but I can't seem to get them to compile correctly. Can anyone help me with what I'm doing wrong?

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    ok

    I don't really understand how you want the code placed in the window. I was confused by the instructions, so if you could offer a better explanation, that would help me greatly.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    i think this is right

    Code:
    #include <ben.h>
    #include <stdio.h>
    
    unsigned int file_func(char dir[], char dir2[])
    {
     FILE *fp, *fp2;
    
     fp = fopen(dir, "r");
     fp2 = fopen(dir2, "w");
     fclose(fp);
     fclose(fp2);
     return 0;
    }
    I get a ton of error messages, saying things like "Symbol Undefined." I can make DLLs with functions that don't use <stdio.h> or other headers, but when I try to include header files, it doesnt work right.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    header

    here is my header code for <ben.h>:

    Code:
    #ifndef BEN_H
    #define BEN_H 1
    unsigned int file_func(char dir[], char dir2[]);
    #endif

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    You need to post the actual error messages.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    ok

    I'll have to look at them. I'll have them posted sometime soon

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    errors

    this code actually works:

    Code:
    #include <dlldemo.h>
    
    unsigned int foo(unsigned int i)
    {
      return i / 2;
    }
    
    unsigned int bar(unsigned int i)
    {
      return i / 3;
    }
    this code doesn't, and has these error messages:

    Code:
    #include <dll.h>
    
    unsigned int filecopy(FILE *ipf, FILE *opf)
    {
     int c;
    
     while ((c = getc(ipf)) != EOF)
      putc(c, opf);
    }
    Error 42: Symbol Undefined _GetCurrentThreadId@0
    Error 42: Symbol Undefined _CreateSemaphoreA@16
    Error 42: Symbol Undefined _ReleaseSemaphore@12

    and the list goes on. Any idea what Im doing wrong?

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Make sure you have <stdio.h>, directly or indirectly.

    What are you linking with? Why do you have <dll.h> instead of <dlldemo.h>?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    well..

    <dlldemo.h> was a library that I got from a website, and <dll.h> was a library of mine to prototype the function. Here is the code for both of them:

    dlldemo.h:
    Code:
    #ifndef DLLDEMO_H
    #define DLLDEMO_H 1
    unsigned int foo(unsigned int i);
    unsigned int bar(unsigned int i);
    #endif
    dll.h:
    Code:
    #ifndef _DLL_H_
    #define _DLL_H_
    
    #include <stdio.h>
    
    unsigned int filecopy(FILE *ipf, FILE *opf);
    
    #endif
    My compiler does everything on its own. All I do is type "dmc dlldemo.c dlldemo.dll" and it compiles

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    unsigned int filecopy(FILE *ipf, FILE *opf)
    {
     int c;
    
     while ((c = getc(ipf)) != EOF)
      putc(c, opf);
    }
    Other than the fact that you don't return a value and you don't include <stdio.h> (which is where FILE is defined), there's nothing wrong with this code. Nothing that should be producing linker errors. Try the code (with a void return value) in a separate program.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    code use

    I've used this code before, and it always worked perfectly, but when I try to make it into a DLL file, I get those error messages. I dont understand what I'm doing wrong. Can you maybe explain how I'd go about making these into a DLL file? I just forgot that I changed the return type, so I'll cange it back.

  12. #12
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    also...

    also, my source file uses <dll.h>, which includes <stdio.h>

  13. #13
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I'm getting 'Symbol Undefined' messages while linking

    Symbol Undefined
    A symbol remained undefined after all input files, including libraries, had been processed. Common causes for this are:

    * A function was called in your code, but the function was never written.
    * A virtual function was declared, but never written.
    * A data variable was referenced, but never defined anywhere.
    * Did not specify all the .obj files to the linker.
    * The calling conventions of the function being referenced do not match the calling conventions of the defined function. Compiler switches, memory models, and special keywords can all affect calling convention (and thereby the name of the symbol as it appears in the .obj file).
    * One or more missing library files (.lib). One way to figure out which .lib file contains the missing symbol is to run:

    \dm\bin\grep symbolname \dm\lib\*.*


    * The LIB environment variable is missing or not pointing to the \dm\lib directory or wherever the .lib files reside.
    The FAQ: http://www.digitalmars.com/faq.html

  14. #14
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    help!

    well, what i cant understand is why it allows me to make some DLLs, but not others. I'm not using any of the symbols or anything that it is saying... any idea as to why it compiles code that has no header files included, but not ones that do?

  15. #15
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    You need to link to kernel32.dll, and that should get rid of those errors. Read the digitalmars FAQ that Tonto linked to in his last post to figure out how to link to libraries. The import library name (assuming your compiler can link to import libraries) is kernel32.lib

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. A question about file streams.
    By Lawn Gnomusrex in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2008, 06:05 AM
  3. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21