//卡序列号缓冲
        unsigned char myserial[5];
        unsigned char status;
        //函数指针声明
        unsigned char (__stdcall *idr_read)(unsigned char *serial);
        //提示当前目录
        AnsiString FileName=ExtractFilePath(Application->ExeName);
         //如果中没有"\"字符,就加进去
        if(FileName.SubString(FileName.Length(),1) != "\\")
        {
             FileName += "\\";
        }        FileName += "OUR_IDR.dll";
        if(!FileExists(FileName))
        {//如果文件不存在
                ShowMessage("无法在应用程序的文件夹找到ID卡读卡器动态库");
                return; //返回
        }
        HINSTANCE hDll;
        //加载动态库
        hDll=LoadLibrary(FileName.c_str());
        //提取动态库
        idr_read = (unsigned char (__stdcall * idr_read)(unsigned char *serial))GetProcAddress(hDll," idr_read ");
        //调用函数
        status = idr_read (myserial);
        //返回值处理
        switch(status)
        {
                case 0:
                        //TO-DO相应的处理,请在以下加入代码
                        break;
                case 1:
                        break;
                //...
         }
谢谢 大家了

解决方案 »

  1.   

            [System.Runtime.InteropServices.DllImport("OUR_IDR.dll", EntryPoint = "idr_read")]
            public static extern byte idr_read(char[] serial);
            private void Form1_Load(object sender, EventArgs e)
            {            char[] myserial = new char[5];
                byte status = idr_read(myserial);
                switch (status)
                {
                    case 0:
                        break;
                    case 1:
                        break;
                }
            }将OUR_IDR.dll和你的程序放在一个目录下,或放在系统的system32文件夹下http://www.cnblogs.com/xumingming/archive/2008/10/10/1308248.html