How to declare the function?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: How to declare the function?

  1. #1
    Join Date
    Feb 2002
    Posts
    3,788

    Angry How to declare the function?

    I have this function exported by a DLL written in C.

    Code:
    PvcsGetRevisionInfo2(
    ARCHIVEHANDLE hArchive, /* Input */
    unsigned char * fileName, /* Input */
    unsigned char * revision, /* Input */
    unsigned char ** author, /* Output */
    unsigned char ** versions, /* Output */
    unsigned char ** promoGroups, /* Output */
    unsigned char ** lockers, /* Output */
    unsigned char ** descr, /* Output */
    unsigned char * resultBuf, /* Input */
    unsigned bufLen, /* Input */
    void * reserved) /* Reserved */

    Now, I want to be able to use this function in my code, but i can't seem to be able to declare it right.
    Below is how the function prototype is currently looking:
    Code:
    [DllImport("Vmwfdtk.dll", CallingConvention=CallingConvention.Cdecl)]
    		public static extern int PvcsGetRevisionInfo2(int hArchive,
    			string fileName, /* Input */
    			string revision, /* Input */
    			StringBuilder author, /* Output */
    			StringBuilder versions, /* Output */
    			StringBuilder promoGroups, /* Output */
    			StringBuilder lockers, /* Output */
    			StringBuilder descr, /* Output */
    			StringBuilder resultBuf, /* Input */
    			int bufLen, /* Input */
    			string reserved /* Reserved */
    			);
    If i call the function above i have nothing in author, versions, promoGroups, lockers, descr.


    Can you help?thanks

  2. #2
    Join Date
    Feb 2002
    Posts
    3,788
    i can't believe that i'm the only one that has tried this...really noone can help?!

  3. #3
    Join Date
    Feb 2002
    Posts
    3,788

    I know I'm in the wrong forum, but i really need it bad...so please bear me

    I posted this yesterday in C Sharp forum, but it seems that no one was able to respond. Can you help?

    I have this function exported by a DLL written in C.

    Code:
    PvcsGetRevisionInfo2(
    ARCHIVEHANDLE hArchive, /* Input */
    unsigned char * fileName, /* Input */
    unsigned char * revision, /* Input */
    unsigned char ** author, /* Output */
    unsigned char ** versions, /* Output */
    unsigned char ** promoGroups, /* Output */
    unsigned char ** lockers, /* Output */
    unsigned char ** descr, /* Output */
    unsigned char * resultBuf, /* Input */
    unsigned bufLen, /* Input */
    void * reserved) /* Reserved */

    Now, I want to be able to use this function in my C Sharp code, but i can't seem to be able to declare it right.
    Below is how the function prototype is currently looking:
    Code:
    [DllImport("Vmwfdtk.dll", CallingConvention=CallingConvention.Cdecl)]
    		public static extern int PvcsGetRevisionInfo2(int hArchive,
    			string fileName, /* Input */
    			string revision, /* Input */
    			StringBuilder author, /* Output */
    			StringBuilder versions, /* Output */
    			StringBuilder promoGroups, /* Output */
    			StringBuilder lockers, /* Output */
    			StringBuilder descr, /* Output */
    			StringBuilder resultBuf, /* Input */
    			int bufLen, /* Input */
    			string reserved /* Reserved */
    			);
    If i call the function above i have nothing in author, versions, promoGroups, lockers, descr.

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871
    First of all declare your function (in C) with __stdcall declaration. Secondly, not all data types can be imported this way - i am not sure about this thing but try using char* instead of unsigned char*.
    Hint: Do some tricks with simple functions like int arguments and returns and then move forward...
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #5
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    5550' N 3739' E
    Posts
    1,503
    i think instead of string builder, you should opt for "ref string", give it a try.
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

  6. #6
    Join Date
    Feb 2002
    Posts
    3,788
    the function is declared like this:
    Code:
    PVCS_APIENTRY PvcsGetRevisionInfo2(
    	ARCHIVEHANDLE logHandle,		/* I: Archive handle */
    	PVCS_PUCHAR fileName,			/* I: Name of logfile or workfile */
    	PVCS_PUCHAR revision,			/* I: Revision to retrieve */
    	PVCS_PUCHAR *author,			/* O: Userid that created revision */
    	PVCS_PUCHAR *versions,			/* O: Version labels assigned to revision */
    	PVCS_PUCHAR *promoGroups,		/* O: Promotion groups assigned to revision */
    	PVCS_PUCHAR *lockers,			/* O: Userids that own a lock on revision */
    	PVCS_PUCHAR *descr,				/* O: Change description for revision */
    	PVCS_PUCHAR resultBuf,			/* I: Buffer to contain results */
    	unsigned bufLen,				/* I: Length of buffer */
    	void *reserved);
    where:
    Code:
    #ifndef PVCS_APIENTRY
    #define PVCS_APIENTRY __declspec(dllexport) int
    #endif
    
    #ifndef PVCS_PUCHAR
    #define PVCS_PUCHAR  char *
    #endif

    The second thing is that after the function call I have a good data for 1 dimension array PVCS_PUCHAR resultBuf, for example, but not for 2 dimensions array PVCS_PUCHAR *promoGroups...
    Last edited by Alin; May 28th, 2004 at 03:13 AM.

  7. #7
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871
    Sorry guy.. I have no idea...
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  8. #8
    Join Date
    Feb 2002
    Posts
    3,788
    nevermind, thanks anyway.

  9. #9
    Join Date
    May 2004
    Posts
    14
    If Andy's suggestion doesn't work, try this. Don't know if it will work however. But it seems to me when you set an object as "out" it will need to give a pointer to the object pointer to the requested function.

    Code:
    [DllImport("Vmwfdtk.dll", CallingConvention=CallingConvention.Cdecl)]
    public static extern int PvcsGetRevisionInfo2(int hArchive,
    	[in] string fileName, /* Input */
    	[in] string revision, /* Input */
    	[out] string author, /* Output */
    	[out] string versions, /* Output */
    	[out] string promoGroups, /* Output */
    	[out] string lockers, /* Output */
    	[out] string descr, /* Output */
    	[in] string resultBuf, /* Input */
    	int bufLen, /* Input */
    	string reserved /* Reserved */
    	);
    Last edited by Viperius; May 28th, 2004 at 05:03 AM.

  10. #10
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    5550' N 3739' E
    Posts
    1,503
    [moved & Merged]

    Alin, keep patience. guru's dont sit here all the time. in a day or two, you will get the answer.

    look at the answers in the C# forum, may be they would help you.
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

  11. #11
    Join Date
    Feb 2002
    Posts
    3,788
    already (yesterday) tried both [out] and [ref]. no luck .
    As I said, if i have a char *ch1Dim, then it's fine if I use StringBuilder, but if I have char **ch2Dim it doesn't return anything in the StringBuilder, neither it does in string, nor in char [], or string [].

    should i try something like:
    Code:
    [MarshalAs(UnmanagedType.LPArray)] String [] ar
    [MarshalAs(UnmanagedType.LPArray, ArraySubType= UnmanagedType.LPStr)] String [] ar
    thanks

  12. #12
    Join Date
    Feb 2002
    Posts
    3,788

    look at the answers in the C# forum, may be they would help you.
    already did. there's nothing about 2 dimensions arrays that helps.

  13. #13
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    5550' N 3739' E
    Posts
    1,503
    try StringCollection class.
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center