Access Navision Stream From DotNet
Simple example how to pass Navision stream (InStream/OutStream) to COM DLL written in .NET (Framework 2.0).
VS2005 solution and sample Navision object are included in archive. Current example reading picture from Item.Picture field and saving it to disk.
Thank you everybody who kicked my in right direction (wakestar, chrido, TonyH and Reflector (tool) )
http://www.mibuso.com/dlinfo.asp?FileID=776
Discuss this download here.
Comments
I've just one small annotation: Close the Streamwriter before return the flag1 value. So you can access the file with an extern process, otherwise first Navision has to be closed. Because the file handle will not be released.
Greets from Switzerland
Andy
Does anyone have an example on how to pass a stream back to navision?
I wan't to pass the string representation of a msxml.xmldom to a .NET-Com-Controller and back to navision by using the stream objects in navision.
Why do you use 0xafc8 in byte[] buffer1 = new byte[0xafc8];?
I see that you can't get the length of the IStream object, so you have to initialize the byte array with a assumed maximum, but why 0xafc8?
thanks & best regards
tobias
Simple example how to pass Navision stream (InStream/OutStream) to COM DLL written in .NET (Framework 2.0).
VS2005 solution and sample Navision object are included in archive. Current example reading picture from Item.Picture field and saving it to disk.
Thank you everybody who kicked my in right direction (wakestar, chrido, TonyH and Reflector (tool) )
Update 21.12.2006:
+ Added code to import data into NAV.
http://www.mibuso.com/dlinfo.asp?FileID=776
Discuss this download here.
Thanks for that sample.
I am making a DLL to convert any image format to BMP format to allow Navision show that.
The DLL have 2 functions, the first one get data from a Navision Stream and save it to a Bitmap variable with the original format, and the second return this Bitmap in BMP format to Navision Stream.
The first function works correctly and save the image, but the second one I do not obtain that it gives back stream directly, that I must pass it to a temporary BMP file and read it and pass it to a stream.
This is the code of the second function:
And this is the code with temporary file:
I think that I am reading bad stream.
Thanks for all.
PD: I can upload the VS2005 project to you if needed. I don't know if if this is the correct place to put it.
PD2: sorry for my bad English.
I've been messing around with getting this to work, but without any effort. It seems like there is no way to use the IStream interface out of .NET
The sample does not compile for me either. Here is what the linker says:
When trying to use the IStream interface directly, it tells me the following:
I use a fresh installation of VS 2005 Professional with SP1 (?) extension. According to Navisions Application Designers Guide, Navision is able to use VT_STREAM (with is IStream) and maps it to its In-/Outstream types in C/SIDE. To be honest, i think this sample does not work at all, because it uses VARIANT instead of IStream.
There must be a working way to use the IStream interface out of C#.NET, but how? Any ideas?
To be true, I tried it and it worked for me. Ok, I did some minor (but may be irrelevant) changes:
I'm running VS2005 .NET express edition and Navision 5.0.
The project compiled as downloaded except the warnings you mentioned and an unused int variable "bytes", which I deleted. As the compiler said, the MarshalAs directive is ignored, I deleted it, too and the project finally compiled without any warnings. To make things easy, I checked "Register for COM Interop" in the project properties and what shall I say, it worked promptly (I tested only the LoadFromNavision method since it is the only one I will need for the moment...) -
Many Thanks to Alexey for this very usefull sample piece of code.
I'm using the code given in NAV4.03. It works great. But the problem is: it crash randomly. Sometimes it success; somtimes just memory error.
Sometimes NAV error saying cannot read from empty BLOB.
any one has the some experience?
I had also crashes. You have to be very careful with multiple threads. I have a queue before raising the data into Navision as an event. Then I'm waiting till the event has finished and i get the returnvalue, manual garbage collection, waiting additional a few ticks and then raise the next blob into Navision.
With Navision 3.70a i never had these problems.
... I personally see this solution as a hack and under normal circumstances I wouldn't use it in production, but their is currently no better solution which provides a similar performance.
If you receive a very general error message "Object reference not set to an instance of an object", be sure to check whether you InStream in Navision is created properly.
Hope this saves you a couple of hours...