Problem in calling unmanaged win32 dll in webservice code

Discussion in 'ASP .Net Web Services' started by tomar, Oct 17, 2007.

  1. tomar

    tomar Guest

    Hi All,

    I Made a win32 dll named with Test.dll in VC++6.0 using following code

    /
    ******************************************************************************
    ** FUNCTION: ASum
    *******************************************************************************/
    extern "C" __declspec(dllexport) int ASum(int a, int b)
    {
    return (a+b);
    }


    When I Use this Test.dll (Unmanaged code) in WebService(Managed code)
    written in C# like

    public class AldorWeb : System.Web.Services.WebService
    {
    [DllImport("Test.dll", SetLastError = false)]
    public static extern int ASum(int a,int b);

    public AldorWeb()
    {
    //CODEGEN: This call is required by the ASP.NET Web
    Services Designer
    InitializeComponent();
    }
    [WebMethod]
    public bool SUM()
    {
    try
    {
    int x = ASum(2, 3);
    }
    catch(Exception e)
    {
    LogWriter.WriteLog(1, 1, (int)enLogType.eTraceLog,e.ToString());
    }
    }
    }

    it gives error like "Unable to load DLL (Test.dll)." if I call SUM
    webmethod. while same code in Windows Application is working fine.

    I think that Permission might be an issue but don't know how to
    implement it. I use Impersonation also but no benefit. even I tried to
    use this code using class library written in C# and called this
    library in webservice but useless.


    Please suggest me some solujtions.


    Thanks all.
    Dharmendra Singh Tomar
    Metadesign Solutions
     
    tomar, Oct 17, 2007
    #1
    1. Advertising

  2. tomar

    tomar Guest

    On Oct 17, 6:13 pm, tomar <> wrote:
    > Hi All,
    >
    > I Made a win32 dll named with Test.dll in VC++6.0 using following code
    >
    > /
    > ***************************************************************************­***
    > ** FUNCTION: ASum
    > ***************************************************************************­****/
    > extern "C" __declspec(dllexport) int ASum(int a, int b)
    > {
    > return (a+b);
    >
    > }
    >
    > When I Use this Test.dll (Unmanaged code) in WebService(Managed code)
    > written in C# like
    >
    > public class AldorWeb : System.Web.Services.WebService
    > {
    > [DllImport("Test.dll", SetLastError = false)]
    > public static extern int ASum(int a,int b);
    >
    > public AldorWeb()
    > {
    > //CODEGEN: This call is required by the ASP.NET Web
    > Services Designer
    > InitializeComponent();
    > }
    > [WebMethod]
    > public bool SUM()
    > {
    > try
    > {
    > int x = ASum(2, 3);
    > }
    > catch(Exception e)
    > {
    > LogWriter.WriteLog(1, 1, (int)enLogType.eTraceLog,e.ToString());
    > }
    > }
    >
    > }
    >
    > it gives error like "Unable to load DLL (Test.dll)." if I call SUM
    > webmethod. while same code in Windows Application is working fine.
    >
    > I think that Permission might be an issue but don't know how to
    > implement it. I use Impersonation also but no benefit. even I tried to
    > use this code using class library written in C# and called this
    > library in webservice but useless.
    >
    > Please suggest me some solujtions.
    >
    > Thanks all.
    > Dharmendra Singh Tomar
    > Metadesign Solutions


    ======================================
    Hi All,

    I have seen putting dll in System32 folder and in C drive as
    well.........Error remains same.


    Dharmendra Singh Tomar
    Metadesign solutions
     
    tomar, Oct 17, 2007
    #2
    1. Advertising

  3. "tomar" <> wrote in message
    news:...
    > Hi All,
    >
    > I Made a win32 dll named with Test.dll in VC++6.0 using following code
    >
    > /
    > ******************************************************************************
    > ** FUNCTION: ASum
    > *******************************************************************************/
    > extern "C" __declspec(dllexport) int ASum(int a, int b)
    > {
    > return (a+b);
    > }
    >
    >
    > When I Use this Test.dll (Unmanaged code) in WebService(Managed code)
    > written in C# like
    >
    > public class AldorWeb : System.Web.Services.WebService
    > {
    > [DllImport("Test.dll", SetLastError = false)]
    > public static extern int ASum(int a,int b);
    >
    > public AldorWeb()
    > {
    > //CODEGEN: This call is required by the ASP.NET Web
    > Services Designer
    > InitializeComponent();
    > }
    > [WebMethod]
    > public bool SUM()
    > {
    > try
    > {
    > int x = ASum(2, 3);
    > }
    > catch(Exception e)
    > {
    > LogWriter.WriteLog(1, 1, (int)enLogType.eTraceLog,e.ToString());
    > }
    > }
    > }
    >
    > it gives error like "Unable to load DLL (Test.dll)." if I call SUM
    > webmethod. while same code in Windows Application is working fine.
    >
    > I think that Permission might be an issue but don't know how to
    > implement it. I use Impersonation also but no benefit. even I tried to
    > use this code using class library written in C# and called this
    > library in webservice but useless.



    Did you place the dll in the bin\ directory?

    In fact, are you running VS2005 SP1, and is this an "ASP.NET Web Service
    Application", or did you create it with File->New->Web Site?

    Also, please include the entire, literal, exception that you receive.
    --
    --------------------------------------------------------------------------------
    John Saunders | MVP - Windows Server System - Connected System Developer
     
    John Saunders [MVP], Oct 17, 2007
    #3
  4. tomar

    tomar Guest

    On Oct 17, 8:44 pm, "John Saunders [MVP]" <john.saunders at
    trizetto.com> wrote:
    > "tomar" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > Hi All,

    >
    > > I Made a win32 dll named with Test.dll in VC++6.0 using following code

    >
    > > /
    > > ***************************************************************************­***
    > > ** FUNCTION: ASum
    > > ***************************************************************************­****/
    > > extern "C" __declspec(dllexport) int ASum(int a, int b)
    > > {
    > > return (a+b);
    > > }

    >
    > > When I Use this Test.dll (Unmanaged code) in WebService(Managed code)
    > > written in C# like

    >
    > > public class AldorWeb : System.Web.Services.WebService
    > > {
    > > [DllImport("Test.dll", SetLastError = false)]
    > > public static extern int ASum(int a,int b);

    >
    > > public AldorWeb()
    > > {
    > > //CODEGEN: This call is required by the ASP.NET Web
    > > Services Designer
    > > InitializeComponent();
    > > }
    > > [WebMethod]
    > > public bool SUM()
    > > {
    > > try
    > > {
    > > int x = ASum(2, 3);
    > > }
    > > catch(Exception e)
    > > {
    > > LogWriter.WriteLog(1, 1, (int)enLogType.eTraceLog,e.ToString());
    > > }
    > > }
    > > }

    >
    > > it gives error like "Unable to load DLL (Test.dll)." if I call SUM
    > > webmethod. while same code in Windows Application is working fine.

    >
    > > I think that Permission might be an issue but don't know how to
    > > implement it. I use Impersonation also but no benefit. even I tried to
    > > use this code using class library written in C# and called this
    > > library in webservice but useless.

    >
    > Did you place the dll in the bin\ directory?
    >
    > In fact, are you running VS2005 SP1, and is this an "ASP.NET Web Service
    > Application", or did you create it with File->New->Web Site?
    >
    > Also, please include the entire, literal, exception that you receive.
    > --
    > ---------------------------------------------------------------------------­-----
    > John Saunders | MVP - Windows Server System - Connected System Developer-Hide quoted text -
    >
    > - Show quoted text -


    ==================================================
    Hi John,
    First of all thanks for your quick response .My comments are
    below as the answer of your questions.

    1. Yes I have Placed the dll in bin\ directory.
    2. My Application is an webservice application.
    3. I am using Dotnet Framwork 1.1.4322.
    4. Exception : System.DllNotFoundException
    Message : Unable to load DLL (Test.dll).
    Is there any restriction in this version? As far as I think If we are
    calling functions of kernel32.dll, User32.dll and advapi32.dll.
    Application is working fine for these built in dll's. What can be the
    issue if I use User created Dll and this dll is perfectly loading in
    windows application in C#.


    Regards,
    Dharmendra Singh Tomar
     
    tomar, Oct 18, 2007
    #4
  5. tomar

    tomar Guest

    On Oct 18, 9:42 am, tomar <> wrote:
    > On Oct 17, 8:44 pm, "John Saunders [MVP]" <john.saunders at
    >
    >
    >
    >
    >
    > trizetto.com> wrote:
    > > "tomar" <> wrote in message

    >
    > >news:...

    >
    > > > Hi All,

    >
    > > > I Made a win32 dll named with Test.dll in VC++6.0 using following code

    >
    > > > /
    > > > ***************************************************************************­­***
    > > > ** FUNCTION: ASum
    > > > ***************************************************************************­­****/
    > > > extern "C" __declspec(dllexport) int ASum(int a, int b)
    > > > {
    > > > return (a+b);
    > > > }

    >
    > > > When I Use this Test.dll (Unmanaged code) in WebService(Managed code)
    > > > written in C# like

    >
    > > > public class AldorWeb : System.Web.Services.WebService
    > > > {
    > > > [DllImport("Test.dll", SetLastError = false)]
    > > > public static extern int ASum(int a,int b);

    >
    > > > public AldorWeb()
    > > > {
    > > > //CODEGEN: This call is required by the ASP.NET Web
    > > > Services Designer
    > > > InitializeComponent();
    > > > }
    > > > [WebMethod]
    > > > public bool SUM()
    > > > {
    > > > try
    > > > {
    > > > int x = ASum(2, 3);
    > > > }
    > > > catch(Exception e)
    > > > {
    > > > LogWriter.WriteLog(1, 1, (int)enLogType.eTraceLog,e.ToString());
    > > > }
    > > > }
    > > > }

    >
    > > > it gives error like "Unable to load DLL (Test.dll)." if I call SUM
    > > > webmethod. while same code in Windows Application is working fine.

    >
    > > > I think that Permission might be an issue but don't know how to
    > > > implement it. I use Impersonation also but no benefit. even I tried to
    > > > use this code using class library written in C# and called this
    > > > library in webservice but useless.

    >
    > > Did you place the dll in the bin\ directory?

    >
    > > In fact, are you running VS2005 SP1, and is this an "ASP.NET Web Service
    > > Application", or did you create it with File->New->Web Site?

    >
    > > Also, please include the entire, literal, exception that you receive.
    > > --
    > > ---------------------------------------------------------------------------­­-----
    > > John Saunders | MVP - Windows Server System - Connected System Developer- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > ==================================================
    > Hi John,
    > First of all thanks for your quick response .My comments are
    > below as the answer of your questions.
    >
    > 1. Yes I have Placed the dll in bin\ directory.
    > 2. My Application is an webservice application.
    > 3. I am using Dotnet Framwork 1.1.4322.
    > 4. Exception : System.DllNotFoundException
    > Message : Unable to load DLL (Test.dll).
    > Is there any restriction in this version? As far as I think If we are
    > calling functions of kernel32.dll, User32.dll and advapi32.dll.
    > Application is working fine for these built in dll's. What can be the
    > issue if I use User created Dll and this dll is perfectly loading in
    > windows application in C#.
    >
    > Regards,
    > Dharmendra Singh Tomar- Hide quoted text -
    >
    > - Show quoted text -


    =====================================================================================

    Hi all,

    I got the Problem, Actually this Project includes another project
    which creates .Lib file as output So dependency of this project is on
    other project. If I remove All the dependency It gets Called fine. But
    Problem Is here that I have to call this dll with dependency on .Lib
    file. I put that Lib file in webservice's bin folder with dll but same
    error comes.

    Please help me to resolve this issue.

    Dharmendra Singh Tomar
    MetaDesign Solutions
     
    tomar, Oct 18, 2007
    #5
  6. tomar

    tomar Guest

    On Oct 18, 1:07 pm, tomar <> wrote:
    > On Oct 18, 9:42 am, tomar <> wrote:
    >
    >
    >
    >
    >
    > > On Oct 17, 8:44 pm, "John Saunders [MVP]" <john.saunders at

    >
    > > trizetto.com> wrote:
    > > > "tomar" <> wrote in message

    >
    > > >news:...

    >
    > > > > Hi All,

    >
    > > > > I Made a win32 dll named with Test.dll in VC++6.0 using following code

    >
    > > > > /
    > > > > ***************************************************************************­­­***
    > > > > ** FUNCTION: ASum
    > > > > ***************************************************************************­­­****/
    > > > > extern "C" __declspec(dllexport) int ASum(int a, int b)
    > > > > {
    > > > > return (a+b);
    > > > > }

    >
    > > > > When I Use this Test.dll (Unmanaged code) in WebService(Managed code)
    > > > > written in C# like

    >
    > > > > public class AldorWeb : System.Web.Services.WebService
    > > > > {
    > > > > [DllImport("Test.dll", SetLastError = false)]
    > > > > public static extern int ASum(int a,int b);

    >
    > > > > public AldorWeb()
    > > > > {
    > > > > //CODEGEN: This call is required by the ASP.NET Web
    > > > > Services Designer
    > > > > InitializeComponent();
    > > > > }
    > > > > [WebMethod]
    > > > > public bool SUM()
    > > > > {
    > > > > try
    > > > > {
    > > > > int x = ASum(2, 3);
    > > > > }
    > > > > catch(Exception e)
    > > > > {
    > > > > LogWriter.WriteLog(1, 1, (int)enLogType.eTraceLog,e.ToString());
    > > > > }
    > > > > }
    > > > > }

    >
    > > > > it gives error like "Unable to load DLL (Test.dll)." if I call SUM
    > > > > webmethod. while same code in Windows Application is working fine.

    >
    > > > > I think that Permission might be an issue but don't know how to
    > > > > implement it. I use Impersonation also but no benefit. even I triedto
    > > > > use this code using class library written in C# and called this
    > > > > library in webservice but useless.

    >
    > > > Did you place the dll in the bin\ directory?

    >
    > > > In fact, are you running VS2005 SP1, and is this an "ASP.NET Web Service
    > > > Application", or did you create it with File->New->Web Site?

    >
    > > > Also, please include the entire, literal, exception that you receive.
    > > > --
    > > > ---------------------------------------------------------------------------­­­-----
    > > > John Saunders | MVP - Windows Server System - Connected System Developer- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > ==================================================
    > > Hi John,
    > > First of all thanks for your quick response .My comments are
    > > below as the answer of your questions.

    >
    > > 1. Yes I have Placed the dll in bin\ directory.
    > > 2. My Application is an webservice application.
    > > 3. I am using Dotnet Framwork 1.1.4322.
    > > 4. Exception : System.DllNotFoundException
    > > Message : Unable to load DLL (Test.dll).
    > > Is there any restriction in this version? As far as I think If we are
    > > calling functions of kernel32.dll, User32.dll and advapi32.dll.
    > > Application is working fine for these built in dll's. What can be the
    > > issue if I use User created Dll and this dll is perfectly loading in
    > > windows application in C#.

    >
    > > Regards,
    > > Dharmendra Singh Tomar- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > ===========================================================================­==========
    >
    > Hi all,
    >
    > I got the Problem, Actually this Project includes another project
    > which creates .Lib file as output So dependency of this project is on
    > other project. If I remove All the dependency It gets Called fine. But
    > Problem Is here that I have to call this dll with dependency on .Lib
    > file. I put that Lib file in webservice's bin folder with dll but same
    > error comes.
    >
    > Please help me to resolve this issue.
    >
    > Dharmendra Singh Tomar
    > MetaDesign Solutions- Hide quoted text -
    >
    > - Show quoted text -


    ----------------------------------------------

    Strange!!!!!

    I am not getting whts happening.

    1. Its not a security issue bcos DLL is being loaded successfully if
    there is no dependency on other file
    2. In Windows application without including LIB dll is being loaded
    and function is called successfully.

    Regards
    Dharmendra Singh tomar
    MetaDesign Solutions
     
    tomar, Oct 18, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    572
  2. GAH
    Replies:
    0
    Views:
    521
  3. Mario Sandvoss

    'unmanaged' - DLL in .NET (C++-Webservice)

    Mario Sandvoss, Jul 1, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    225
    Mario Sandvoss
    Jul 1, 2004
  4. vikrantca

    Error calling unmanaged dll from webservice

    vikrantca, Nov 11, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    217
    vikrantca
    Nov 11, 2005
  5. Adam M. Rosenzweig

    Problem with .NET WebService Loading Unmanaged DLL

    Adam M. Rosenzweig, Mar 6, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    200
    Adam M. Rosenzweig
    Mar 6, 2006
Loading...

Share This Page