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 8 1264
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"
<Ra*****@discussions.microsoft.com> 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
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" <Ra*****@discussions.microsoft.com> 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
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"
<Ra*****@discussions.microsoft.com> 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" <Ra*****@discussions.microsoft.com> 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
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" <Ra*****@discussions.microsoft.com> 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" <Ra*****@discussions.microsoft.com> 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
Without knowing the sig of the native function it is hard to say what
you might want to pass.
Perhaps CLRSpy could detect the problem: http://www.gotdotnet.com/Community/U...5-ad09ef3bb37f
--
Scott http://www.OdeToCode.com/blogs/scott/
On Sun, 5 Jun 2005 07:11:02 -0700, "Ravneet"
<Ra*****@discussions.microsoft.com> wrote: 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" <Ra*****@discussions.microsoft.com> 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" >> <Ra*****@discussions.microsoft.com> 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 >> >>
Hi Scott,
I will run the CLRSpy to narrow the cause. Meanwhile the sig of the native is:
LPSTR APIENTRY getSerialEx();
it is declared in the managed code as:
static extern string getSerialEx();
What I am not able to understand is that why it works the first time around
and fails in successive sessions. I must remind you that this code is being
called from Session_Start of the ASP.NET web application. To narrow down
issues if I do a LoadLibrary just before the call it returns all the time
with a valid module handle. So the DLL is loaded but the call to the function
fails from second instance onwards. Now, this sounds like some memory not
being released issue. I am gonna do some more tests, meanwhile if you (or
anyone else) has something to suggest, pls do.
Thanks
Ravneet
"Scott Allen" wrote: Without knowing the sig of the native function it is hard to say what you might want to pass.
Perhaps CLRSpy could detect the problem: http://www.gotdotnet.com/Community/U...5-ad09ef3bb37f
-- Scott http://www.OdeToCode.com/blogs/scott/
On Sun, 5 Jun 2005 07:11:02 -0700, "Ravneet" <Ra*****@discussions.microsoft.com> wrote:
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" <Ra*****@discussions.microsoft.com> 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" >> <Ra*****@discussions.microsoft.com> 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 >> >>
Yes - it does sound odd. Is there anychance something in this unmanged
method uses thread local storage? If that is the case it would have to
be invoked on the same thread everytime, else exhibit wierd behavior.
--
Scott http://www.OdeToCode.com/blogs/scott/
On Sun, 5 Jun 2005 10:19:29 -0700, "Ravneet"
<Ra*****@discussions.microsoft.com> wrote: Hi Scott, I will run the CLRSpy to narrow the cause. Meanwhile the sig of the native is:
LPSTR APIENTRY getSerialEx();
it is declared in the managed code as: static extern string getSerialEx();
What I am not able to understand is that why it works the first time around and fails in successive sessions. I must remind you that this code is being called from Session_Start of the ASP.NET web application. To narrow down issues if I do a LoadLibrary just before the call it returns all the time with a valid module handle. So the DLL is loaded but the call to the function fails from second instance onwards. Now, this sounds like some memory not being released issue. I am gonna do some more tests, meanwhile if you (or anyone else) has something to suggest, pls do.
Thanks Ravneet
I dont think there is any threal local storage involved in the C++ code. I
will have to confirm this from the author of the DLL though. As far as I can
see it is just a registry call that gets done in the unmanaged code, to get a
string entry, and returned back.
"Scott Allen" wrote: Yes - it does sound odd. Is there anychance something in this unmanged method uses thread local storage? If that is the case it would have to be invoked on the same thread everytime, else exhibit wierd behavior.
-- Scott http://www.OdeToCode.com/blogs/scott/
On Sun, 5 Jun 2005 10:19:29 -0700, "Ravneet" <Ra*****@discussions.microsoft.com> wrote:
Hi Scott, I will run the CLRSpy to narrow the cause. Meanwhile the sig of the native is:
LPSTR APIENTRY getSerialEx();
it is declared in the managed code as: static extern string getSerialEx();
What I am not able to understand is that why it works the first time around and fails in successive sessions. I must remind you that this code is being called from Session_Start of the ASP.NET web application. To narrow down issues if I do a LoadLibrary just before the call it returns all the time with a valid module handle. So the DLL is loaded but the call to the function fails from second instance onwards. Now, this sounds like some memory not being released issue. I am gonna do some more tests, meanwhile if you (or anyone else) has something to suggest, pls do.
Thanks Ravneet
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rawCoder |
last post by:
Hi All,
I have a *.cer file, a public key of some one and I want to encrypt some
thing using this public key.
Can someone point me to a sample code for Encrypting some file using...
|
by: Mike |
last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta;
frameworkv2.0.50215 ) the source code below I get errors (listed below due to
the use of ICallBackEventHandler. Ultimately I...
|
by: Christopher Benson-Manica |
last post by:
Why can't I use a class destructor in a using declaration:
using MyClass::~MyClass;
?
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org ...
|
by: beliavsky |
last post by:
Many of my C++ programs have the line
using namespace std;
but the "Accelerated C++" book of Koenig and Moo has many examples
where the library names are included one at a time, for example
...
|
by: Petter Reinholdtsen |
last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to
compile a program using 'using namespace std;' at the top. The reason
seem to be that the compiler refuses to accept 'using...
| |
by: john.burton.email |
last post by:
I've done some extensive searching and can't seem to find an answer to
this -
Is it correct to using "using" with templates, for example:
using std::vector;
Or do I need to specify the type...
|
by: Enos Meroka |
last post by:
Hallo,
I am a student doing my project in the university.. I have been trying
to compile the program using HP -UX aCC compiler, however I keep on
getting the following errors.
...
|
by: Calum Grant |
last post by:
In older C++ computer books, you'll often see
using namespace std;
even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered
better to qualify names to make it clearer what...
|
by: JDeats |
last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting
and decrypting a file.
http://support.microsoft.com/kb/307010
In .NET 2.0 this approach is not fully supported (a .NET 2.0...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |