Click here to Skip to main content
15,850,299 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I swear, I've tried everything I've found online, and I'm still getting a PINVOKE error.
"A call to PInvoke function 'BioPacVideo!BioPacVideo.VideoWrapper::SetFName' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

on the C# side

        public static extern void SetFName(StringBuilder FName, int FStart);
        //public static extern void SetFName([MarshalAs(UnmanagedType.LPStr)]string FName, int FStart);

on the C++ side
extern "C" _declspec(dllexport) void SetFName(LPTSTR FName, int FileStart);
Updated 2-Mar-11 11:55am

1 solution

I immediately can see a mistake: you use LPStr which will marshal 1-byte null-terminated string, but you need platform-dependent string (LPTSTR).

Try this:
public static extern void SetFName(
    [MarshalAs(UnmanagedType.LPTStr)]string FName,
    int FStart);

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900