Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem calling an external C++ dll

Status
Not open for further replies.

NeilTrain

Programmer
May 27, 2003
275
0
0
US
I have a C# application that uses a legacy C++ dll that runs an operation on a set of Images. During testing some of the output images created by the dll had strange artifacts in them, weird cropping and resizing going on that it wasn't supposed to do.

After some pretty intensive testing it appears that I can get any image to render just fine after my C# app starts, but if I change the source image, I start to get errors. So I restart the app, and this time begin with the image that gave me errors… several renders, but this time no problem, if I switch to the image that was ok the first run, now that one gives me problems. It appears the external call only causes these weird issues after the input image parameters have changed.

My call to the external dll is within a method, and all of the objects that get passed to this DLL are created WITHIN that method (local scope), so new ones are created for each call. Below is the method call, as well as the DllImport declaration.

Is there a way to ensure each call is “fresh” just like the first one after the app starts? It seems the only way to ensure the external call goes OK is to restart my C# app before doing another render with new parameters.

Code:
Public void render()
{
            string CFX = "<proprietary render script goes here>";
            byte[] LocalCacheDir = Encoding.Default.GetBytes(Config.Paths.ImageCacheDir); 
            byte[] url_spec = Encoding.Default.GetBytes(CFX);
            int usr_num = -1;
            StringBuilder type = new StringBuilder(string.Empty);
            StringBuilder image = new StringBuilder(string.Empty);
            byte[] outputFile = Encoding.Default.GetBytes(Config.Paths.RenderedImage.FullPath);
            bool result = GenerateImageExt(LocalCacheDir, url_spec, usr_num, type, image, outputFile);
}

[DllImport("cfxengineext.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)] 
        static extern bool GenerateImageExt(
            byte[] LocalCacheDir,
            byte[] url_spec,
            int user_num,
            [MarshalAs(UnmanagedType.LPStr)] StringBuilder type,
            [MarshalAs(UnmanagedType.LPStr)] StringBuilder image,
            byte[] outputFile
            );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top