Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 650997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:06:52+00:00 2026-05-13T22:06:52+00:00

I have .lib file with its header (.h) file. This file have a few

  • 0

I have .lib file with its header (.h) file. This file have a few functions that need to be used in C# application.

After googling I found that I need to create a dynamic DLL from this static library and call this dynamic DLL from C# code using interop.

  1. I have created a win32 project and selected type DLL.

  2. Included header file and added .lib to additional dependencies.

    I am able to see the functions defined in the static library (when I press ctrl + space).

As a total newbie I do not know how I can export the function, which is, in .lib with following signature:

void testfun( char* inp_buff, unsigned short* inp_len, char* buffer_decomp,unsigned *output_len,unsigned short *errorCode)

I want same signature in my dynamic DLL with a different name.

What to write in header file and .cpp file?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:06:52+00:00Added an answer on May 13, 2026 at 10:06 pm

    If you can recompile your lib, just add __declspec(dllexport) to the signatures of all of the functions you want to be exported.

    void __declspec(dllexport) testfun( char* inp_buff, unsigned short* inp_len, char* buffer_decomp,unsigned *output_len,unsigned short *errorCode)
    

    If you can’t do that, then you can export them by writing a .def file instead. Using def files you can even change the name of a function as it is exported.
    http://msdn.microsoft.com/en-us/library/28d6s79h.aspx

    —- contents of mylib.def —-

    LIBRARY
    
    EXPORTS
       testfun
       newname=testfun2
    

    Then when you link the dll, include mylib.def

    link /dll /machine:x86 /def:mylib.def  mylib.lib
    

    Edit2:

    note that pinvoke assumes that the functions you import will have _stdcall calling convention unless you say otherwise. So you might need to do this as well, in your C# code.

    [DllImport("mylib.dll", CallingConvention=CallingConvention.Cdecl)]
    

    Or, you could change your C++ code to be __stdcall

    void __declspec(dllexport) __stdcall testfun( char* inp_buff, ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
I have a JAR-file in the WEB-INF/lib directory of my project that is displayed
I have a jar file that I want to put in the shared lib
I have the .def file, .lib file, the .dll, the source files. It's using
I have downloaded ffmpeg lib file and complied it for armv7. I added ffmpeg
I have a lib/languages.py file only with a dict format e.g.: en = {}
I have the following file hierarchy: Lib > MyModule.rb Lib > MyModule.rb > MyClass.rb
I'm not sure what I'm doing wrong here, I have a file in lib/acts_as_votable.rb
I have a custom jar file in the tomcat lib/ folder. As per my
Given a postscript file that has the following header %!PS-Adobe-3.0 I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.