MFC调用VC动态链接库中的函数总是报错解决方法

MFC调用VC动态链接库中的函数总是报错
各位好!其中Portnumber(串口号)、baudrate(波特率)是我自己定义的一个全局变量。现在情况:串口我可以通过测试按钮成功打开,但是调用动态链接库中的函数老是调用出错!是不是我设置的参数不对?返回结果为0,说明函数调用成功。才疏学浅,也不知道问题出在啥地方,困扰好久了,望高人指点一二!
下面是我打开计算机串口连接外设的程序:
void CDlg1::OnButton1() //测试按钮
{
       CString port;       //选择想要打开的串口号
HANDLE  hCom;       //串口句柄
       if( m_radiobutton3 == 0) //0表示串口被选上,1表示网口被选上
{
((CComboBox*)GetDlgItem(IDC_COMBO1))->GetWindowText(m_portnumber);   //取得下拉框当前内容
port="COM"+ m_portnumber;  //添加的代码
hCom = CreateFile(port,             //用CreateFile函数打开串口
GENERIC_READ | GENERIC_WRITE,   //访问模式允许读写
0,                              //不共享
NULL,                           //默认安全模式
OPEN_EXISTING,                  //打开方式:打开已经存在的端口
//FILE_FLAG_OVERLAPPED,           //异步工作方式 
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,//异步I/O重叠结构 
NULL);

if(hCom == INVALID_HANDLE_VALUE)    //无效的句柄值

strMsg = "串口" + m_portnumber + "打开失败";
AfxMessageBox(strMsg); 
CloseHandle(hCom); 
hCom  =  0;   
}
else
{
                        //调用动态链接库中的连接到指定串口OpenComPort函数
unsigned char freaderaddr = 0x00; //原先读写器的地址
long fCmdRet;  //调用动态链接库中OpenComPort函数的返回值
typedef long (WINAPI *lpAddFun)(long,unsigned char,unsigned char,long);
HINSTANCE HDLL;  //加载动态链接库,返回DLL文件的句柄 
lpAddFun addFun; //函数指针
HDLL= LoadLibrary("UHFReader18.dll"); //加载动态链接库UHFReader18.dll文件
if (HDLL != NULL)
{
addFun=( lpAddFun) GetProcAddress(HDLL, "OpenComPort");//得到所加载DLL模块中OpenComPort函数的地址
if (addFun != NULL)
{
fCmdRet = addFun( portnumber, freaderaddr, baudrate, (long)hCom );
}
CString strMsg;
strMsg.Format(_T("%ld"),fCmdRet);
AfxMessageBox( strMsg); //测试返回结果

FreeLibrary(HDLL);//释放已经加载的DLL模块
}
                 }
}

MFC调用VC动态链接库中的函数总是报错解决方法这个是动态链接库中我需要调用函数的介绍!
------解决方案--------------------
加上dll代码,一起联调
------解决方案--------------------
HDLL= LoadLibrary("UHFReader18.dll");
如果HDLL为空,说明读取没有成功,你用绝对路径试试。
然后用setcurrentdirectory设置当前路径
------解决方案--------------------
LoadLibrary
The LoadLibrary function maps the specified executable module into the address space of the calling process. 

HINSTANCE LoadLibrary(
  LPCTSTR lpLibFileName   // address of filename of executable module
);
 
Parameters
lpLibFileName 
Pointer to a null-terminated string that names the executable module (either a .DLL or .EXE file). The name specified is the filename of the module and is not related to the name stored in the library module itself, as specified by the LIBRARY keyword in the module-definition (.DEF) file. 
If the string specifies a path but the file does not exist in the specified directory, the function fails. When specifying a path, be sure to use backslashes (\), not forward slashes (/). 

If the string does not specify a path, the function uses a standard search strategy to find the file. See the Remarks for more information. 

Return Values
If the function succeeds, the return value is a handle to the module.

If the function fails, the return value is NULL. To get extended error information, call GetLastError. 

Remarks
LoadLibrary can be used to map a DLL module and return a handle that can be used in GetProcAddress to get the address of a DLL function. LoadLibrary can also be used to map other executable modules. For example, the function can specify an .EXE file to get a handle that can be used inFindResource orLoadResource. Do not use LoadLibrary to "run" a .EXE file.