Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / August 2004

Tip: Looking for answers? Try searching our database.

Object reference not set to an instance of an object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doru - 19 Aug 2004 00:27 GMT
Hi all,

I have a windows service that is calling a function from an unmanaged dll.

The C++ declaration is : (char *) getxmlRequest(const char *szHostName,
unsigned short usPort, const int nNetTimeout, void *xml, int size);

My C# declarations are:

[DllImport("xmlinterop.dll",
EntryPoint="getxmlRequest",ExactSpelling=false,CallingConvention=CallingConvention.StdCall,SetLastError=true)]

static extern string getxmlRequest([MarshalAs(UnmanagedType.LPStr)] string
server,UInt16 port,Int32 timeout,[MarshalAs(UnmanagedType.LPStr)] string buf
,Int32 length);           

If I run this code in a WIndows application, I have no errors, but running
in the service application I get:
"Object reference not set to an instance of an object".

Any ideas?

Thanks,

Doru
Robert Jordan - 19 Aug 2004 14:36 GMT
hi doru,

> If I run this code in a WIndows application, I have no errors, but running
> in the service application I get:
> "Object reference not set to an instance of an object".
>
> Any ideas?

where is the exception exactly coming from? please post the
whole exception with its stacktrace.

i'm supposing the unmanaged code doesn't cope well
when called by a service. it might access the registry
or something not available to a service.

bye
rob
Doru - 22 Aug 2004 00:39 GMT
Hi Robert,

I think it is a problem of Garbage Collector.
I will try GC.KeepAlive(returnedString)

Doru

> hi doru,
>
[quoted text clipped - 13 lines]
> bye
> rob
Phil Wilson - 22 Aug 2004 19:34 GMT
Output strings are usually interoped as StringBuilder. Declare it as
StringBuilder, then you'd allocate it first then use it as the return
result. Something like:
StringBuilder ret = new StringBuilder (100);
ret = getxmlRequest(...)
Signature

Phil Wilson
[MVP Windows Installer]

> Hi Robert,
>
[quoted text clipped - 20 lines]
> > bye
> > rob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.