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

  • Home
  • SEARCH
  • 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 9033109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:08:51+00:00 2026-06-16T08:08:51+00:00

I have a dll created in c++ which exports function using the .def file.The

  • 0

I have a dll created in c++ which exports function using the .def file.The function is written as follows:

__declspec(dllexport) int __stdcall MethodA(int par1,int par2,char *par3)
{....} 

and then the method is declared in the .def file as

MethodA       @1

Now my question is how can I use this method in my C# application ?
I tried adding the dll file as a reference in my C# application and I get the following message

"A reference to the filename.dll could not be added please make sure that the file is accessible and that the file is a valid assembly or COM component."

Edit:
After readings the comments posted here. I am attempting to use the file in the following manner

 [DllImport("C:\\Filename.dll")]
        public static extern int MethodA(int par1,int par2,String par3);

and the I am using it as such

 MethodA(1,2,"SomeString);

This is the error I am getting

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
  • 1 1 Answer
  • 0 Views
  • 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-06-16T08:08:52+00:00Added an answer on June 16, 2026 at 8:08 am

    While you did fine AFAIK on the C++ side, you need to do more on the C# side, You need to create a C# method declaration as something like this:

    [DllImport ("your_dll_name")]
    extern int MethodA (int par1, int par2);
    

    Decorate with static, unsafe etc. as desired and needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a DLL which exports a function that creates a window using
Just created a .dll file that has some methods. And I have a another
I have created an ActiveX dll using VB6 and packaged it using the Package
I am using IIS 6 on 2003. I have created a HTTP handler dll
I have some MSVC++ compiled DLL's for which I have created COM-like (lite) interfaces
I have a dll created in c# which does some database operation upon calling.
I have created dll in C# 3.5 which does some memory intensive matrix calculations
I have application which can export slides to PowerPoint. I'm using Microsoft.Office.Interop.PowerPoint.dll . This
I have .NET 3.5 web application which uses some COM dll created in VB6.
I have a project created using Visual Studio 2008 targeting .NET 3.5 which makes

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.