首页 \ 问答 \ LINUX 如何查看JPG文件

LINUX 如何查看JPG文件

更新时间:2022-06-13 20:06

最满意答案

1. 先新建一个名为 hello.cpp 的 C++ 源文件:
Cpp代码  
#include 
  


 #define DLLEXPORT extern "C" __declspec(dllexport)  

DLLEXPORT int 
 __stdcall hello()  
{  
    printf("Hello world!\n");  
    return 0;  
}  

2. 编译成 dll 文件:

Cpp代码  
cl /LD hello.cpp  

注意, 这里的参数是 /LD, 而不是 /DL。

3. 编写一个名为 hello.py 的 python 文件:

Python代码  
# coding: utf-8  

import os  
import ctypes  

CUR_PATH = os.path.dirname(
 __file__)  

if __name__ == '__main__':  
    print 'starting...'  
    dll = ctypes.WinDLL(os.path.join(CUR_PATH, 'hello.dll'))  
    dll.hello()  

4. 输出为:

Python代码  
starting...  
Hello world!  

需要注意的地方:
1. C++ 的 dll 中的接口函数必须以 extern "C" __declspec(dllexport) 为前缀, C 的以 __declspec(dllexport) 为前缀。
否则会报错:

Python代码  
Traceback (most recent call last):  
  File "hello.py", line 12, in 
 
    
    dll.hello()  
  File "C:\Python25\lib\ctypes\__init__.py", line 361, in __getattr__  
    func = self.__getitem__(name)  
  File "C:\Python25\lib\ctypes\__init__.py", line 366, in __getitem__  
    func = self._FuncPtr((name_or_ordinal, self))  
AttributeError: function 'hello' not found
 

其他回答

这个在python的帮助里就有。例子代码也完整。参考”extending and embedding the python interpreter“, 还有"python/c api reference manual". 后面还有一段说明。
the api is equally usable from c++, but for brevity it is generally referred to 
as the python/c api。

不过有两个建议:

最好用c语言,而不是用c++。这主要是保持兼容性,方便使用ctypes, c++略复杂些。

另外就是建议你使用cython,这样挺容易就生成python 的ext,所以不用再为c++编译python ext发愁。

如果想在c++里调用python也容易。初始化一个interpreter,就和python一样用。通过返回变量获得结果。

另外c++与python程序数据交换还可以采用共享内存,其中有一个是基于numpy的共享内存方案挺成熟的。

相关问答

更多
  • python是一款应用非常广泛的脚本程序语言,谷歌公司的网页就是用python编写。python在生物信息、统计、网页制作、计算等多个领域都体现出了强大的功能。python和其他脚本语言如java、R、Perl 一样,都可以直接在命令行里运行脚本程序。工具/原料 python;CMD命令行;windows操作系统 方法/步骤 1、首先下载安装python,建议安装2.7版本以上,3.0版本以下,由于3.0版本以上不向下兼容,体验较差。 2、打开文本编辑器,推荐editplus,notepad等,将文件保存成 ...
  • 如果经过stdcall声明的方法,如果不是用def文件声明的导出函数或者extern “C” 声明的话,编译器会对函数名进行修改;在编译加上extern C;这样就OK了; 另外可以在PYTHON代码里试试这样: ctypes.cdll.LoadLibrary("dllpath")
  • 1. 先新建一个名为 hello.cpp 的 C++ 源文件: Cpp代码 #include #define DLLEXPORT extern "C" __declspec(dllexport) DLLEXPORT int __stdcall hello() { printf("Hello world!\n"); return 0; } 2. 编译成 dll 文件: Cpp代码 cl /LD hello.cpp 注意, 这里的参数是 /LD, 而不是 /DL。 3. 编写一个名为 hello.py 的 py ...
  • 可以的调用,python中一般有两种方法调用DLL中的函数: 1、直接使用函数名,函数名可以用dependency walker等工具查看。(这个工具在vc或者vs的工具包中) [python] view plaincopy import ctypes dll = CTYPES.CDLL("test.dll") res = test(3, 4) 2、使用Ordinal,Ordinal可以用dependency walker等工具查看。 [python] view plaincopy import ctype ...
  • dll文件,有两种调用标准约定。 你使用Python调用dll文件,先了解一下Python使用的dll调用标准。
  • 点击Settings按钮>选择Project Interpreter; 可以在右侧切换Python版本; 在此之前必须将Python的路径加入系统环境变量
  • 听起来就像您安装了不兼容的Python版本,或者使用错误的设置编译了DLL。 DLL和Python解释器都必须是32或64位。 Sounds like you have an incompatible version of Python installed or the DLL was compiled using the wrong settings. The DLL and the Python interpreter both have to be either 32 or 64 Bit.
  • MSVC通过编译指示支持此功能: #pragma comment(lib, "python25.lib"); 更多信息在MSDN 。 查看Python.h文件并修改链接的名称,如果这是你想要的。 MSVC supports this feature through pragmas: #pragma comment(lib, "python25.lib"); More info in MSDN. Look into Python.h file and modify the name of the link ...
  • 获取: http : //www.dependencywalker.com/ ,使用depends.exe打开DLL,然后在“视图”菜单中激活“Undecorate C ++ Functions”。 我主要使用它来查找依赖项,但它也暴露了DLL的入口点。 这不是万无一失的,因为暴露类的DLL不必导出其方法。 例如,纯虚方法布局足够统一,您可以将实例公开为可能是工厂函数的接口指针。 但它可能会解决您的问题。 无论如何,您需要一个依赖性walker的副本。 :) Get this: http://www.dep ...
  • 鉴于问题中提供的信息,解决方案是: import ctypes lib = ctypes.CDLL(r'C:\Users\toto\FIProtocol.dll') CommOpen = getattr(lib, "?CommOpen@CFIPcmd@@QAEJEJ@Z") CommOpen.argtypes = [c_byte, c_long] CommOpen.restype = c_long 现在它准备打电话: l = CommOpen(5 ,115200) 一些说明: 使用CDLL而不是Win ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)