Accessing a windows DLL with interop
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Accessing a windows DLL with interop

  1. #1
    Join Date
    Aug 2000
    Posts
    48

    Accessing a windows DLL with interop

    Hello Folks
    I'm trying to access a regular windows 32 dll ( not a COM dll ) through .NET interop and I'm getting an exception EntryPointNotFoundException.

    DLL was created using VS6. Following is the DLL code.

    =================================================
    #include "stdafx.h"

    BOOL APIENTRY DllMain( HANDLE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved
    )
    {
    return TRUE;
    }


    _declspec(dllexport) int Jumbo(int x)
    {
    return 11;
    }
    ==================================================

    Following is the .NET code (VS2008)
    *********************************************************

    using System.Runtime.InteropServices ;

    public partial class Form1 : Form
    {
    [DllImport(@"C:\inprogress\CPP\TestDLL\Debug\TestDLL.DLL")]
    public static extern int Jumbo(int x) ;

    public Form1()
    {
    InitializeComponent();
    }

    private void cmdClick_Click(object sender, EventArgs e)
    {
    int y = Jumbo(1); ///This call throws exception

    }
    }

    **************************************************

    Now I tested the DLL with dll walker and I can see the exports. Also
    I made another application using VC++ 6, and called the function in the DLL
    successfully.


    Could anyone tell me what is it I'm doing wrong?

    thx
    gulu.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Accessing a windows DLL with interop

    This was asked literally 4 days ago and is on the second page of this forum:

    http://www.codeguru.com/forum/showthread.php?t=508635

  3. #3
    Join Date
    Aug 2000
    Posts
    48

    Re: Accessing a windows DLL with interop

    thank you BigEd. It gave me a clue. I need to declare the function


    extern "C" _declspec(dllexport) int Jumbo(int x)

    and it does the trick.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center