Help with using c++ class called with P/Invoke

This is a discussion on Help with using c++ class called with P/Invoke within the C# Programming forums, part of the General Programming Boards category; I am trying to build a web application that uses p/invoke to access a method. Similiar to the one used ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    4

    Help with using c++ class called with P/Invoke

    I am trying to build a web application that uses p/invoke to access a method. Similiar to the one used here -

    http://cboard.cprogramming.com/csharp-programming/114635-help-using-cplusplus-class-called-p-invoke.html


    However I keep getting the following error message -

    Unable to load DLL 'MyDll.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    Any solutions I read say to change the output directory to match that of the Mydll directory I have tried that and it still does not work.

    Any help would be appreciated I've been at this for days now.

    thanks

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Does your dll has the name MyDll.dll and is it located in the same directory that your executable is?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    Yeh my dll has the name MyDll.dll. I tried putting it in the bin directory of my SampleWebApp. But this does not work. I was following this tutorial -
    P/Invoke Tutorial: Basics (Part 1) manski's blog
    And got it working using c# console application but can't get it to work as a web application.

    I changed the build output path of SampleWebApp to the Debug folder as the tutorial suggests but this does not work.
    I have read that ASp.NET ignores this path when you click the debug button (F5) and goes to the bin folder.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    I have MyDll class added as a project to the SampleWebApp application.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Use the full path. So, rather than...

    Code:
    [DllImport("MyLib.dll")]
    ...you must use something like...

    Code:
    [DllImport("c:\inetpub\wwwroot\MyWebPage\bin\MyLib.dll")]

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    yeh that worked thanks.

    I tried before and it didn't work but it works now. thanks

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Or check what Environment.CurrentDirectory returns and use a relative path to your dll. Thats a bit safer and a little more freedom to move your app around

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-08-2012, 12:39 AM
  2. Help with using c++ class called with P/Invoke
    By dudeomanodude in forum C# Programming
    Replies: 2
    Last Post: 05-10-2009, 01:38 AM
  3. Invoke IE
    By baddog in forum Windows Programming
    Replies: 2
    Last Post: 01-29-2008, 02:56 PM
  4. Problem with invoke of hooks DLL
    By arti_valekar in forum Windows Programming
    Replies: 1
    Last Post: 03-02-2005, 03:06 PM
  5. Class function that returns the instance it's called from
    By L Boksha in forum C++ Programming
    Replies: 4
    Last Post: 05-25-2002, 12:52 PM

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