【MS CLR】咨询进度条混合编程接口问题?

CLR编写

C#调用

结果崩了,这个不晓得怎么测试,单从代码层面能看出错误不呢?

Parents
  • 试了下clr,貌似挺正常的

    #pragma once
    
    #include <Mstn/MdlApi/msdialog.fdf>
    #include <vcclr.h>
    
    namespace Test
    {
    	public ref class ProcessBarHelper
    	{
    	public:
    		ProcessBarHelper()
    		{
    			dialog = NULL;
    		}
    		void OpenBar(System::String^ message)
    		{
    			pin_ptr<const wchar_t> msg = PtrToStringChars(message);
    			if (dialog == NULL)
    				dialog = mdlDialog_completionBarOpen(msg);
    		}
    		void CloseBar()
    		{
    			mdlDialog_completionBarClose(dialog);
    		}
    		void UpdateBar(System::String^ message, int percent)
    		{
    			pin_ptr<const wchar_t> msg = PtrToStringChars(message);
    			mdlDialog_completionBarUpdate(dialog, msg, percent);
    		}
    		~ProcessBarHelper()
    		{
    			dialog = NULL;
    		}
    
    	private:
    		MSDialogP dialog;
    	};
    }
    
    //ProcessBarHelper.cpp
    #include "ProcessBarHelper.h"
    
    //C#
    Test.ProcessBarHelper processBarHelper = new Test.ProcessBarHelper();
    processBarHelper.OpenBar("1");
    System.Threading.Thread.Sleep(1000);
    for (int i = 1; i <= 100; i++)
    {
        processBarHelper.UpdateBar( $"更新{i}", i );
        System.Threading.Thread.Sleep(200);
    }
    processBarHelper.CloseBar();

    Answer Verified By: aoteman 

Reply
  • 试了下clr,貌似挺正常的

    #pragma once
    
    #include <Mstn/MdlApi/msdialog.fdf>
    #include <vcclr.h>
    
    namespace Test
    {
    	public ref class ProcessBarHelper
    	{
    	public:
    		ProcessBarHelper()
    		{
    			dialog = NULL;
    		}
    		void OpenBar(System::String^ message)
    		{
    			pin_ptr<const wchar_t> msg = PtrToStringChars(message);
    			if (dialog == NULL)
    				dialog = mdlDialog_completionBarOpen(msg);
    		}
    		void CloseBar()
    		{
    			mdlDialog_completionBarClose(dialog);
    		}
    		void UpdateBar(System::String^ message, int percent)
    		{
    			pin_ptr<const wchar_t> msg = PtrToStringChars(message);
    			mdlDialog_completionBarUpdate(dialog, msg, percent);
    		}
    		~ProcessBarHelper()
    		{
    			dialog = NULL;
    		}
    
    	private:
    		MSDialogP dialog;
    	};
    }
    
    //ProcessBarHelper.cpp
    #include "ProcessBarHelper.h"
    
    //C#
    Test.ProcessBarHelper processBarHelper = new Test.ProcessBarHelper();
    processBarHelper.OpenBar("1");
    System.Threading.Thread.Sleep(1000);
    for (int i = 1; i <= 100; i++)
    {
        processBarHelper.UpdateBar( $"更新{i}", i );
        System.Threading.Thread.Sleep(200);
    }
    processBarHelper.CloseBar();

    Answer Verified By: aoteman 

Children
No Data