开发者

C++ library works in vb6 but not in c#

I'm writing a C# application that has to consume a C++ api provided by my customer. The library works fine when it's referenced by a vb6 application, but when I reference it in my c# application and try to call the same methods, I get a different (wrong) behavior. The methods I'm calling take a couple of string arguments. Provided that I don't have the library's source code, I can only guess what could be wrong and this leads me to the following thought: Is it possible that the library could have been designed to be called from vb6 only? I mean for example, that it could be expecting the string parameters to be encoded in a certain way different from the one c# uses. If so, is there any workaround for this? So far the best I could do was to create a vb6 wrapper ocx, but it's not any elegant and least of all easy to deploy solution.

I'm posting the code which initializes the object:


        ApiPrnClass apiprn;      /开发者_StackOverflow社区/ this is the class imported form the com reference
        for (int j = 0; j < 10; j++)
        {
            apiprn = new ApiPrnClass();  
            apiprn.FMGetModel(_TIPODISPOSITIVO.iDocument);
            apiprn.FMPRNFormat(_TIPODISPOSITIVO.iDocument, _TIPOFORMATO.DEL_CONDENSED, "");
            apiprn.PRNBeforePrint(_TIPODISPOSITIVO.iDocument, "");

            for (int i = 0; i < 10; i++)
            {
                
                string linea = "TEST C/ BUFF XXX-----------------------".Replace("XXX", (10 * j + i).ToString().PadLeft(3, '0'));
                apiprn.FMPrint(_TIPODISPOSITIVO.iDocument, linea);
            }

            
            apiprn.PRNAfterPrint(_TIPODISPOSITIVO.iDocument);
            System.Threading.Thread.Sleep(1000);
        }

I would appreciate any help, Thanks, Bernabé


I can't believe the cause of the problem, I found it myself. I realized that the library was doing fine when called from a c# console application but wrong when used from a winforms (didn't mention it before, it was a library intended to print a ticket). The only difference i knew there could be between the two types of application is that the console application runs a thread dedicated to the runing code while the winforms goes to check the event qeue. It seems the library was so twisted-code that it couldn't support that switching. So I tryied calling the library from the windows application but in another thread....and it worked!

Thanks for all the answers anyway, Bernabé

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜