print_file.cpp

本文介绍了一个简单的Windows应用程序实例,包括窗口类注册、消息处理及打印机输出等功能。通过具体代码展示了如何在不同版本的Windows上实现这些功能。

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> 
#include <windows.h> 
#include "Print_File.h"


#if defined (WIN32)
 #define IS_WIN32 TRUE
#else
 #define IS_WIN32 FALSE
#endif

#define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
#define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
#define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32

HINSTANCE hInst;   // current instance

LPCTSTR lpszAppName  = "MyApp";
LPCTSTR lpszTitle    = "My Application";

BOOL RegisterWin95( CONST WNDCLASS* lpwc );

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                      LPTSTR lpCmdLine, int nCmdShow)
{
   MSG      msg;
   HWND     hWnd;
   WNDCLASS wc;

   // Register the main application window class.
   //............................................
   wc.style         = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc   = (WNDPROC)WndProc;      
   wc.cbClsExtra    = 0;                     
   wc.cbWndExtra    = 0;                     
   wc.hInstance     = hInstance;             
   wc.hIcon         = LoadIcon( hInstance, lpszAppName );
   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
   wc.lpszMenuName  = lpszAppName;             
   wc.lpszClassName = lpszAppName;             

   if ( IS_WIN95 )
   {
      if ( !RegisterWin95( &wc ) )
         return( FALSE );
   }
   else if ( !RegisterClass( &wc ) )
      return( FALSE );

   hInst = hInstance;

   // Create the main application window.
   //....................................
   hWnd = CreateWindow( lpszAppName,
                        lpszTitle,   
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, 0,
                        CW_USEDEFAULT, 0, 
                        NULL,             
                        NULL,             
                        hInstance,        
                        NULL              
                      );

   if ( !hWnd )
      return( FALSE );

   ShowWindow( hWnd, nCmdShow );
   UpdateWindow( hWnd );        

   while( GetMessage( &msg, NULL, 0, 0) )  
   {
      TranslateMessage( &msg );
      DispatchMessage( &msg ); 
   }

   return( msg.wParam );
}


BOOL RegisterWin95( CONST WNDCLASS* lpwc )
{
   WNDCLASSEX wcex;

   wcex.style         = lpwc->style;
   wcex.lpfnWndProc   = lpwc->lpfnWndProc;
   wcex.cbClsExtra    = lpwc->cbClsExtra;
   wcex.cbWndExtra    = lpwc->cbWndExtra;
   wcex.hInstance     = lpwc->hInstance;
   wcex.hIcon         = lpwc->hIcon;
   wcex.hCursor       = lpwc->hCursor;
   wcex.hbrBackground = lpwc->hbrBackground;
   wcex.lpszMenuName  = lpwc->lpszMenuName;
   wcex.lpszClassName = lpwc->lpszClassName;

   // Added elements for Windows 95.
   //...............................
   wcex.cbSize = sizeof(WNDCLASSEX);
   wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName,
                            IMAGE_ICON, 16, 16,
                            LR_DEFAULTCOLOR );
   
   return RegisterClassEx( &wcex );
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
      case WM_COMMAND :
              switch( LOWORD( wParam ) )
              {
                 case IDM_TEST :
                        {
                           HDC     hDC;
                           DOCINFO di;

                           // Create a DC for the printer.
                           //.............................
                           hDC = CreateDC( "WINSPOOL", "HP DeskJet 550C",
                                           NULL, NULL );

                           memset( &di, 0, sizeof( DOCINFO ) );
                           di.cbSize      = sizeof( DOCINFO );
                           di.lpszDocName = "Sample Document";

                           // Print a string to the printer.
                           //...............................
                           if ( StartDoc( hDC, &di ) > 0 )
                           {
                              StartPage( hDC );
                              TextOut( hDC, 10, 10,
                                       "This output is to the printer.", 30 );
                              EndPage( hDC );
                              EndDoc( hDC );
                           }
   
                           DeleteDC( hDC );
                        }
                        break;

                 case IDM_ABOUT :
                        DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
                        break;

                 case IDM_EXIT :
                        DestroyWindow( hWnd );
                        break;
              }
              break;
     
      case WM_DESTROY :
              PostQuitMessage(0);
              break;

      default :
            return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
   }

   return( 0L );
}


LRESULT CALLBACK About( HWND hDlg,          
                        UINT message,       
                        WPARAM wParam,      
                        LPARAM lParam)
{
   switch (message)
   {
       case WM_INITDIALOG:
               return (TRUE);

       case WM_COMMAND:                             
              if (   LOWORD(wParam) == IDOK        
                   || LOWORD(wParam) == IDCANCEL)   
               {
                       EndDialog(hDlg, TRUE);       
                       return (TRUE);
               }
               break;
   }

   return (FALSE);
}

<think>好的,用户遇到了chamfer_dist模块中chamfer_cuda.cpp文件缺失的问题,导致FileNotFoundError。我需要分析可能的原因并提供解决方案。 首先,用户提到代码尝试导入chamfer_3D包,如果不存在则加载C++扩展。引用[1]说明torch.utils.cpp_extension.load可能卡住,但这里的问题是文件缺失,可能路径不正确或文件未正确生成。 接下来,用户可能没有正确安装包含C++代码的依赖。引用[2]提到OpenPoints项目中的cpp文件夹有setup.py,需要编译安装。因此,需要检查是否执行了正确的安装步骤,比如运行python setup.py install。如果chamfer_dist的安装脚本未正确编译,可能导致.cpp文件未被复制到正确位置。 另外,引用[3]指出某些仓库可能存在空文件夹,用户可能下载了不完整的代码库,导致chamfer_cuda.cpp缺失。需要确认代码仓库是否完整,或从其他来源获取该文件。 此外,检查文件路径是否正确。如果项目结构复杂,setup.py可能未正确配置,导致文件未被包含。用户需要检查文件是否存在于项目目录中,并调整安装脚本的路径设置。 可能的解决方案包括:重新安装chamfer_dist,确保编译过程完成;手动下载缺失文件;调整文件路径或安装脚本;检查环境依赖如CUDA和PyTorch版本是否匹配。需要逐步指导用户检查每个可能的原因,并提供相应的解决步骤。</think>关于chamfer_dist模块中chamfer_cuda.cpp文件缺失问题的解决方案如下: ### 问题分析 该错误通常发生在以下场景: 1. 第三方库未完整安装(如未执行C++扩展编译) 2. 文件路径引用错误 3. 依赖环境未正确配置[^2] ### 解决方案步骤 1. **验证安装过程** - 进入chamfer_dist项目目录 ```bash cd path/to/chamfer_dist python setup.py install ``` - 检查输出日志是否包含C++编译过程 - 确认生成`build`文件夹及`.cpp`文件转换的`.so`文件[^1] 2. **手动补充文件** - 若发现代码仓库不完整(如示例引用[3]的空文件夹问题) - 从官方仓库单独下载缺失文件: ```bash wget https://raw.githubusercontent.com/author_name/repo_name/master/chamfer_cuda.cpp ``` 3. **调整文件结构** ```python # 修改原始代码中的文件路径 ext = CUDAExtension( name="chamfer_cuda", sources=[ "src/chamfer_cuda.cpp", # 调整为实际路径 "src/chamfer_cuda_kernel.cu" ] ) ``` 4. **环境验证** ```bash # 检查CUDA与PyTorch版本匹配 nvcc --version python -c "import torch; print(torch.__version__)" ``` ### 典型错误排查 ```python # 测试安装是否成功 import torch from chamferdist import ChamferDistance chamfer = ChamferDistance() # 若出现libc10.so错误,需重建conda环境 ``` ### 补充说明 对于引用[4]中提到的复杂项目结构,建议: 1. 按照项目文档重建conda环境 2. 使用`ldd`命令检查动态链接库 3. 确认`LD_LIBRARY_PATH`包含CUDA库路径
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值