#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>__declspec(dllexport) __cdecl int main(int argc, char* argv[])
{
char arg[50]={0};
arg[0]='\"';
strcpy(arg+1,argv[0]);
int len=int(strlen(arg));
arg[len]='\"';
HWND hWnd=FindWindow(NULL,arg); //找到程序运行窗口的句柄
HDC hDC=GetDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄
HPEN hPen,hOldPen; //画笔
int i=0;for(;i<500;++i)
SetPixel(hDC,10+i,10+i,0x0000ff);//用画点的办法画一根线,最后一个参数是颜色(32位)hPen=CreatePen(PS_SOLID,2,0x00ff00);//生成绿色画笔
hOldPen=(HPEN)SelectObject(hDC,hPen);//把画笔引入设备场境
MoveToEx(hDC,20,50,NULL); //设置画线起点
LineTo(hDC,520,550); //画到终点Arc(hDC,100,100,300,300,350,500,350,500);//画圆SelectObject(hDC,hOldPen);
ReleaseDC(hWnd,hDC);//下面是对比,表明它确实是控制台程序printf("hello console");
system("pause");
return 0;}c写的dll
我调用的时候出错?
为什么啊?

解决方案 »

  1.   

    public class dll
    {
    [DllImport("Mydll.dll")]

    public static   extern int main(int argc,string argv); public dll()
    {
    //
    // TODO: 在此处添加构造函数逻辑

    //

    }
    public   void cirlet()
    { main(0,"0");
    }
    }
    补上c#,可提示
    未处理的“System.NullReferenceException”类型的异常出现在 WindowsApplication1.exe 中。其他信息: 未将对象引用设置到对象的实例。
    这样的错误
      

  2.   

    你的Dll有问题吗?写个C++的测试先。而且,Dll里边用main,实在是让人迷惑。
      

  3.   

    HWND hWnd=FindWindow(NULL,arg); //找到程序运行窗口的句柄
    HDC hDC=GetDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄
    这两句都很有嫌疑……
      

  4.   

    public static   extern int main(int argc, ref string argv);
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  5.   

    dll?有问题吗?可以给个正确的研究吗?