Re: DLLInport from a ASP.NET web app using C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Scott,
A sample follows:

<Managed code snippet begins>

public string getSerial()
{
string serial = "";
try{
serial = getSerialEx(); //this line throws NullPointerException
}
catch(Exception npe){
string s = npe.StackTrace;
}
return serial;
}
</managed code snippet ends>

The serial is returned correctly in first run. Keeping the first session on,
I open another browser and browse to the app. This time the call fails,
giving an exception at the line marked above.
On the umanaged code side, the function just returns a LPSTR (tried with
LPTSTR too). Initially the function was taking a LPTSTR out parameter, and I
was using StringBuilder argument in the managed code, but this kept on
returning garbage to me. Played with Charset.XXXX too to fix that but didnt
help much, so changed the unmanaged function to accept no parameters but
return a LPSTR now.
Let me know if you need some more info.

Thanks !
"Scott Allen" wrote:

> Ok, perhaps you could post some of your code. Do you know exactly what
> line throws the null reference exception? You should be able to get
> that information from a stack trace.
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Sat, 4 Jun 2005 19:47:01 -0700, "Ravneet"
> <Ravneet@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> >Scott,
> >that **can** be a very faint case. The unmanaged code works fine as far as i
> >have tested. But still to rule out this case I can do a repeated call to the
> >unmanaged code to see if it works (from unmanaged code itself).
> >As for the case from managed code, the call returns correct string value on
> >the first attempt, and fails with an exception in successive calls.
> >
> >"Scott Allen" wrote:
> >
> >> Is it possible the unmanged code is returning a NULL pointer?
> >>
> >> --
> >> Scott
> >> http://www.OdeToCode.com/blogs/scott/
> >>
> >> On Fri, 3 Jun 2005 15:31:03 -0700, "Ravneet"
> >> <Ravneet@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> >>
> >> >I am trying to do some calls to unmanaged DLL that I have written. I am doing
> >> >it in the Session_Start of my Global.asax.cs.
> >> >The first time I call a function in my DLL it returns correct string value.
> >> >The return type in unmanaged DLL is LPSTR (tried LPTSTR too). There are no
> >> >in/out params in the functions, just a return value.
> >> >The second time (and onwards) when I try to make a call to the same
> >> >function, I get an exception "Object reference not set to an object....)." I
> >> >am trying this by loading multiple page requests to the web app.
> >> >Any ideas where I should look into to resolve this one.
> >> >
> >> >Thanks
> >> >Ravneet
> >>
> >>
>
>
.



Relevant Pages

  • Re: Help for Marshalling
    ... If you need to "return" a string, pass a string pointer as a ... along with another that tells how big that buffer is so the ... Managed Code in the Embedded World ... unsigned char *lpOutBuf; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: debugging mixed mode assembly
    ... Again why do you call this unmanaged code? ... C++/CLI compiles to managed code, ... String^ s; ... I guess you mean from managed code, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Help for Marshalling
    ... Just out of curiosity how do u actually send back a string from ... unsigned char *lpOutBuf; ... Managed Code in the Embedded World ... // LP to a buffer for output data ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Help for Marshalling
    ... Just out of curiosity how do u actually send back a string from ... unsigned char *lpOutBuf; ... Managed Code in the Embedded World ... // LP to a buffer for output data ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Help for Marshalling
    ... Just out of curiosity how do u actually send back a string from ... unsigned char *lpOutBuf; ... Managed Code in the Embedded World ... // LP to a buffer for output data ...
    (microsoft.public.dotnet.framework.compactframework)