源代码:
/********源代码**********/
// DllTest.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;int _tmain(int argc, _TCHAR* argv[])
{
unsigned char in[6];
for(int i=0;i<6;i++){
in[i]='7';
}
unsigned char out[13];
for(int i=0;i<13;i++){
out[i]='0';
}
cout<<out<<endl; HINSTANCE   hDllInst   =   ::LoadLibraryA("sneer.dll"); 
cout<<hDllInst<<endl; if(hDllInst != 0) 

typedef int ( _stdcall pTN_EncryptProcess) (unsigned char *,unsigned char *); 
cout<<"1  "<<hDllInst<<endl;
pTN_EncryptProcess   *My_TN_EncryptProcess   =   NULL;   //   youFuntionNameAlias   函数别名 
cout<<"2  "<<hDllInst<<endl;
My_TN_EncryptProcess =(pTN_EncryptProcess *)GetProcAddress(hDllInst,"TN_EncryptProcess"); 
cout<<"3  "<<hDllInst<<endl;
int result=My_TN_EncryptProcess(out,in); 
cout<<"4  "<<hDllInst<<endl;
FreeLibrary(hDllInst); 
} cout<<out<<endl;
return 0;
}
/********结束**********/注释:
dll文件========== 名为sneer.dll且在Debug文件夹下已存在
dll函数说明为===== int TN_EncryptProcess (unsigned char *out, unsigned char *in);
in - 只允许6个字节全数字的字符串运行结果:

解决方案 »

  1.   

    图片看不到,能把输出结果复制粘贴上来吗?控制台窗口里面的数据也可以复制的。
    猜测:
    把这一行:pTN_EncryptProcess   *My_TN_EncryptProcess   =   NULL;
    修改成pTN_EncryptProcess   My_TN_EncryptProcess   =   NULL;
    就是说,去掉那个星号。
      

  2.   

    另外,这一行 My_TN_EncryptProcess =(pTN_EncryptProcess *)GetProcAddress(hDllInst,"TN_EncryptProcess");  
    也要修改为 My_TN_EncryptProcess =(pTN_EncryptProcess)GetProcAddress(hDllInst,"TN_EncryptProcess");  因为pTN_EncryptProcess本身就带有指针的定义在里面了,不需要在定义一个指针,不然就变成指向函数指针的指针了。
      

  3.   

    晕,再补充,函数指针的定义应该是这样的:typedef int ( _stdcall *pTN_EncryptProcess) (unsigned char *,unsigned char *);  
      

  4.   

    一楼修改方案的编译结果:
    1>DllTest.cpp
    1>c:\documents and settings\lee\my documents\visual studio 2005\projects\dlltest\dlltest.cpp(28) : error C2072: 'My_TN_EncryptProcess' : initialization of a function
    1>c:\documents and settings\lee\my documents\visual studio 2005\projects\dlltest\dlltest.cpp(28) : error C2205: 'My_TN_EncryptProcess' : cannot initialize extern variables with block scope
    1>c:\documents and settings\lee\my documents\visual studio 2005\projects\dlltest\dlltest.cpp(28) : error C2440: 'initializing' : cannot convert from 'int' to 'pTN_EncryptProcess'
    1>        There are no conversions to function types, although there are conversions to references or pointers to functions
    1>c:\documents and settings\lee\my documents\visual studio 2005\projects\dlltest\dlltest.cpp(30) : error C2659: '=' : function as left operand
    1>生成日志保存在“file://c:\Documents and Settings\lee\My Documents\Visual Studio 2005\Projects\DllTest\Debug\BuildLog.htm”
    1>DllTest - 4 个错误,0 个警告
    ========== 全部重新生成: 0 已成功, 1 已失败, 0 已跳过 ==========
      

  5.   

    我编译的时候没有遇到问题啊,你看一下:
    int _tmain(int argc, _TCHAR* argv[])
    {
    unsigned char in[7],out[12];
    HINSTANCE   hDllInst   =   ::LoadLibraryA("sneer.dll");  
    if(hDllInst != 0)  
    {  
    typedef int ( _stdcall *pTN_EncryptProcess) (unsigned char *,unsigned char *);  
    pTN_EncryptProcess   My_TN_EncryptProcess   =   NULL;   //   youFuntionNameAlias   函数别名  
    My_TN_EncryptProcess =(pTN_EncryptProcess)GetProcAddress(hDllInst,"TN_EncryptProcess");  
    int result=My_TN_EncryptProcess(out,in);   
    FreeLibrary(hDllInst);  
    }  system("pause");
    return 0;
    }
      

  6.   


    typedef int ( _stdcall *pTN_EncryptProcess) (unsigned char *,unsigned char *);  
    中的_stdcall删除。