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 / December 2004

Tip: Looking for answers? Try searching our database.

Walking through an Iterator, calling unmanaged code gives error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
M K - 13 Dec 2004 15:57 GMT
The error occures after the function ends. I have posted the code on my weblog:
mkenyon2.blogspot.com
Titled: Okay, latest and greatest on this project.

This project is using VB .Net 1.1
Mattias Sj?gren - 13 Dec 2004 20:30 GMT
>The error occures after the function ends. I have posted the code on my weblog:
>mkenyon2.blogspot.com
>Titled: Okay, latest and greatest on this project.
>
>This project is using VB .Net 1.1

Next time, please include relevant parts of the code in your message
so we don't have to visit your blog to find out wwhat ythe problem is.

It's hard to say what's wrong without seeing the native function
declarations. Some working native calling code would also be helpful.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

M K - 13 Dec 2004 20:49 GMT
Native Def:
//Get the size and type for the specified attribute ID.//
KPDCStatus KPDCGetAttributeInfo(KPDCOpaqueRef inRef, KPDCAttributeID
inAttrID, KPDCDataTypes *outAttrType, KPDCUInt32 *outAttrSize);

My wrap:
Declare Auto Function KGetAttributeInfo Lib "DCSPro4SLR.dll" Alias
"KPDCGetAttributeInfo" (ByVal inRef As IntPtr, ByVal inAttrID As Integer,
ByRef outAttrType As KPDCDataTypes, ByRef outAttrSize As Integer) As Integer

Native Def:
//Get the value of the specified attribute ID. If the attribute is the
KPDCPropValueID of a property, then the value of the property will be
retrieved from the camera.//
KPDCStatus KPDCGetAttributeValue(KPDCOpaqueRef inRef, KPDCAttributeID
inAttrID, KPDCUInt32 *inOutAttrSize,

My wrap:
Declare Auto Function KGetAttributeValue Lib "DCSPro4SLR.dll" Alias
"KPDCGetAttributeValue" (ByVal inRef As IntPtr, ByVal inAttrID As Integer,
ByRef inOutAttrSize As Integer, ByVal outAttrValue As IntPtr) As Integer

Native Def:
//Allocate a property iterator for camera properties.//
KPDCStatus KPDCAllocPropertyIterator ( KPDCCameraRef inCameraRef,
KPDCPropertyIterRef *outRef);

My Wrap:
Declare Auto Function KAllocPropertyIterator Lib "DCSPro4SLR.dll" Alias
"KPDCAllocPropertyIterator" (ByVal inCameraRef As IntPtr, ByRef outRef As
IntPtr) As Integer

Native Code:
//Return a reference to the first item that has the string specified by
inName and the value of its name attribute. The iterator points to the found
item. A subsequent call to KPDCIteratorNext returns the item following the
found item in the list.//
KPDCStatus KPDCIteratorFind(KPDCIteratorRef inIteratorRef, const char
*inName, KPDCOpaqueRef *outFoundItemRef);

My Wrap:
Declare Auto Function KIteratorFind Lib "DCSPro4SLR.dll" Alias
"KPDCIteratorFind" (ByVal inIteratorRef As IntPtr, ByVal inName As
System.Text.StringBuilder, ByRef outFoundItemRef As IntPtr) As Integer

Native Code:
//Return a reference to the next enumerated item. After creating a new
iterator or calling KPDCIteratorReset, this function returns the first item.
If there are no more items, outNextItemRef will not be valid.//
KPDCStatus KPDCIteratorNext(KPDCIteratorRef inIteratorRef, KPDCOpaqueRef
*outNextItemRef);

My Wrap:
Declare Auto Function KIteratorNext Lib "DCSPro4SLR.dll" Alias
"KPDCIteratorNext" (ByVal inIteratorRef As IntPtr, ByRef outNextItemRef As
IntPtr) As Integer

Native Code:
//Reset the iterator to point to the beginning of the list.//
KPDCStatus KPDCIteratorReset(KPDCIteratorRef inIteratorRef);

My Wrap:
Declare Auto Function KIteratorReset Lib "DCSPro4SLR.dll" Alias
"KPDCIteratorReset" (ByVal inIteratorRef As IntPtr) As Integer
Mattias Sj?gren - 19 Dec 2004 23:29 GMT
>My Wrap:
> Declare Auto Function KIteratorFind Lib "DCSPro4SLR.dll" Alias
>"KPDCIteratorFind" (ByVal inIteratorRef As IntPtr, ByVal inName As
>System.Text.StringBuilder, ByRef outFoundItemRef As IntPtr) As Integer

Most of your Declare statements look fine, except perhaps this one
where you should be using Anis rather than Auto.

But your calling code you posted on your blog looks a bit weird. Why
are you initializing all your IntPtr variables to point to a single
byte allocated from the unmanaged heap?

And the first function you call is KIteratorNext. Aren't you supposed
to first initialize the iterator somehow?

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

M K - 13 Dec 2004 20:55 GMT
Thank you for your patience. I noticed this article on your site:
http://support.microsoft.com/?kbid=309327

It breakes unmanaged resources into 2 types, handles to operating system
objects, and non operating system objects.

What would constitute an operating system object?
M K - 13 Dec 2004 21:01 GMT
Sorry I keep doing this, but as I type things out, I'm working it out in my
head. You should also know that in the C++ demo code, they have a typedef
section that looks like this:
TypeDefs in demo C++ code:
typedef void*           KPDCOpaqueRef;
typedef KPDCOpaqueRef   KPDCLibMgrRef;
typedef KPDCOpaqueRef   KPDCIteratorRef;  
typedef KPDCIteratorRef  KPDCCameraIterRef;
typedef KPDCOpaqueRef   KPDCCameraRef;
typedef KPDCIteratorRef  KPDCPropertyIterRef;
typedef KPDCOpaqueRef   KPDCPropertyRef;
typedef KPDCIteratorRef  KPDCDirectoryIterRef;
typedef KPDCOpaqueRef   KPDCDirItemRef;
typedef KPDCOpaqueRef   KPDCIORef;
typedef KPDCOpaqueRef   KPDCImageRef;

Most of the function declarations use these. After looking through the
article I mentioned in the previous reply, I am wondering, should I use
HandleRef instead of IntPtrs? And how do I know when to use what?

I really think that this is something with garbage collection, because it is
happening after the managed function (which calls to the unmanaged function)
is called.
M K - 13 Dec 2004 20:55 GMT
I think I should clarify, the DLLs I am working with communicate with a
camera via FireWire.

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.