易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : c++

c++调用mysql接口以及存储过程

      mysql在sdk中为c语言提供了一些访问接口,我们可以使用这些接口连接并访问mysql数据库,当然也可以调用mysql的存储过程。
例子:
      首先下载mysql的sdk,解压好以后,里面包含一个include,和lib文件夹。我们在自己的工程中包含这两个文件夹的目录,并且设置好连接库选项即可。 我们先建立一个工程,运行下看看,再看其中的代码。
      1.  这里我们使用vs2003建立一个空的window console工程,添加一个cpp源文件。
      2.  拷贝最后面的源代码到cpp文件中。
      3.  设置好工程路径:project --> properity --> c/c++下general选项中Additional include directories选项添加上面说的include目录。  project --> properity --> linker下general选项中Additional library directories中添加上面的lib目录。project --> properity --> linker下input选项中添加libmysql.lib文件。这样我们的工程就设置完毕。
      4.  下面编译 ......

c++调用mysql接口以及存储过程

      mysql在sdk中为c语言提供了一些访问接口,我们可以使用这些接口连接并访问mysql数据库,当然也可以调用mysql的存储过程。
例子:
      首先下载mysql的sdk,解压好以后,里面包含一个include,和lib文件夹。我们在自己的工程中包含这两个文件夹的目录,并且设置好连接库选项即可。 我们先建立一个工程,运行下看看,再看其中的代码。
      1.  这里我们使用vs2003建立一个空的window console工程,添加一个cpp源文件。
      2.  拷贝最后面的源代码到cpp文件中。
      3.  设置好工程路径:project --> properity --> c/c++下general选项中Additional include directories选项添加上面说的include目录。  project --> properity --> linker下general选项中Additional library directories中添加上面的lib目录。project --> properity --> linker下input选项中添加libmysql.lib文件。这样我们的工程就设置完毕。
      4.  下面编译 ......

C#动态调用C++编写的DLL函数


动态加载DLL需要使用Windows API函数:LoadLibrary、GetProcAddress以及FreeLibrary。我们可以使用DllImport在C#中使用这三个函数。

[DllImport("Kernel32")]
public static extern int GetProcAddress(int handle, String funcname);

[DllImport("Kernel32")]
public static extern int LoadLibrary(String funcname);

[DllImport("Kernel32")]
public static extern int FreeLibrary(int handle);

当我们在C++中动态调用Dll中的函数时,我们一般的方法是:
假设DLL中有一个导出函数,函数原型如下:
BOOL __stdcall foo(Object &object, LPVOID lpReserved);

1、首先定义相应的函数指针:
typedef BOOL (__stdcall *PFOO)(Object &object, LPVOID lpReserved);

2、调用LoadLibrary加载dll:
HINSTANCE hInst = ::LoadLibraryW(dllFileName);

3、调用GetProcAddress函数获取要调用函数的地址:
PFOO foo = (PFOO)GetProcAddress(hInst,"foo");
if(foo == NULL)
{
    FreeLibrary(hInst);
    return false;
}

4、调用foo函数:
BOOL bRe ......

C#动态调用C++编写的DLL函数


动态加载DLL需要使用Windows API函数:LoadLibrary、GetProcAddress以及FreeLibrary。我们可以使用DllImport在C#中使用这三个函数。

[DllImport("Kernel32")]
public static extern int GetProcAddress(int handle, String funcname);

[DllImport("Kernel32")]
public static extern int LoadLibrary(String funcname);

[DllImport("Kernel32")]
public static extern int FreeLibrary(int handle);

当我们在C++中动态调用Dll中的函数时,我们一般的方法是:
假设DLL中有一个导出函数,函数原型如下:
BOOL __stdcall foo(Object &object, LPVOID lpReserved);

1、首先定义相应的函数指针:
typedef BOOL (__stdcall *PFOO)(Object &object, LPVOID lpReserved);

2、调用LoadLibrary加载dll:
HINSTANCE hInst = ::LoadLibraryW(dllFileName);

3、调用GetProcAddress函数获取要调用函数的地址:
PFOO foo = (PFOO)GetProcAddress(hInst,"foo");
if(foo == NULL)
{
    FreeLibrary(hInst);
    return false;
}

4、调用foo函数:
BOOL bRe ......

C#动态调用C++编写的DLL函数


动态加载DLL需要使用Windows API函数:LoadLibrary、GetProcAddress以及FreeLibrary。我们可以使用DllImport在C#中使用这三个函数。

[DllImport("Kernel32")]
public static extern int GetProcAddress(int handle, String funcname);

[DllImport("Kernel32")]
public static extern int LoadLibrary(String funcname);

[DllImport("Kernel32")]
public static extern int FreeLibrary(int handle);

当我们在C++中动态调用Dll中的函数时,我们一般的方法是:
假设DLL中有一个导出函数,函数原型如下:
BOOL __stdcall foo(Object &object, LPVOID lpReserved);

1、首先定义相应的函数指针:
typedef BOOL (__stdcall *PFOO)(Object &object, LPVOID lpReserved);

2、调用LoadLibrary加载dll:
HINSTANCE hInst = ::LoadLibraryW(dllFileName);

3、调用GetProcAddress函数获取要调用函数的地址:
PFOO foo = (PFOO)GetProcAddress(hInst,"foo");
if(foo == NULL)
{
    FreeLibrary(hInst);
    return false;
}

4、调用foo函数:
BOOL bRe ......

.net实例:使用C++调用C#的DLL

1 创建C# DLL,需要指定应用类型为“类库”,代码:
namespace CSLib
{
    public class Class1
    {
        private string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = "Your Name: " + value;
            }
     &nb ......

.net实例:使用C++调用C#的DLL

1 创建C# DLL,需要指定应用类型为“类库”,代码:
namespace CSLib
{
    public class Class1
    {
        private string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = "Your Name: " + value;
            }
     &nb ......

.net实例:使用C++调用C#的DLL

1 创建C# DLL,需要指定应用类型为“类库”,代码:
namespace CSLib
{
    public class Class1
    {
        private string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = "Your Name: " + value;
            }
     &nb ......

Developer Support Languages VC++, C# and VB.NET


Welcome to Microsoft Developer Support, Languages team blog! You will find a lot of language related troubleshooting resources here.
Troubleshooting PInvoke Related Issues 
I am back with some more PInvoke Stuff.  Recently I was working on a PInvoke issue which I found interesting. 
I have a C++ dll which has a function whose signature is
int TestFunc(IN_STRUCT in_Params, RET_STRUCT * pret_Par). 
I wanted to call this function from C#.  Function has two arguments.  First argument is input structure which will be filled from C# code and passed to C++ code.  Second argument is output structure which is filled in C++ code and output to C# code.
 Here are the C struct definitions and a function that needs to be marshaled
#include "stdafx.h"
#include <stdio.h>
#include "Objbase.h"
#include <malloc.h>
 
 
typedef struct IN_STRUCT
{
    &nbs ......

Developer Support Languages VC++, C# and VB.NET


Welcome to Microsoft Developer Support, Languages team blog! You will find a lot of language related troubleshooting resources here.
Troubleshooting PInvoke Related Issues 
I am back with some more PInvoke Stuff.  Recently I was working on a PInvoke issue which I found interesting. 
I have a C++ dll which has a function whose signature is
int TestFunc(IN_STRUCT in_Params, RET_STRUCT * pret_Par). 
I wanted to call this function from C#.  Function has two arguments.  First argument is input structure which will be filled from C# code and passed to C++ code.  Second argument is output structure which is filled in C++ code and output to C# code.
 Here are the C struct definitions and a function that needs to be marshaled
#include "stdafx.h"
#include <stdio.h>
#include "Objbase.h"
#include <malloc.h>
 
 
typedef struct IN_STRUCT
{
    &nbs ......

Developer Support Languages VC++, C# and VB.NET


Welcome to Microsoft Developer Support, Languages team blog! You will find a lot of language related troubleshooting resources here.
Troubleshooting PInvoke Related Issues 
I am back with some more PInvoke Stuff.  Recently I was working on a PInvoke issue which I found interesting. 
I have a C++ dll which has a function whose signature is
int TestFunc(IN_STRUCT in_Params, RET_STRUCT * pret_Par). 
I wanted to call this function from C#.  Function has two arguments.  First argument is input structure which will be filled from C# code and passed to C++ code.  Second argument is output structure which is filled in C++ code and output to C# code.
 Here are the C struct definitions and a function that needs to be marshaled
#include "stdafx.h"
#include <stdio.h>
#include "Objbase.h"
#include <malloc.h>
 
 
typedef struct IN_STRUCT
{
    &nbs ......

c,c++风格字串与strcmp

众所周知,strcmp为字串比较只用,简单的函数并不简单。
下面的代码
int main()
{
      char* cp1 = {'z', 'h', 'a', 'n', 'g'};
      char* cp2 = {'z', 'h', 'a', 'n', 'g'};
      std::cout<<strcmp(cp1, cp2)<<std::endl;
      return 0;
}
看到命名两个字符串相等,但是程序竟然输出-1;
什么原因
其实strcmp在比较过程中如果传入的是c风格的字串像下面这样
char* cp1 = "zhang";
char* cp2 = "zhang";
这是实际上比较的是两个字串的首地址,而这两个字面定义的字串都隐含着类型是const
于是他们在内存中具有相同的地址,所以即使比较两个指针的内容(两个串的地址),也会得到
正确的结果。不过仍然很惊讶,对于不同的字串系统竟然能够准确根据其大小在内存中排列
例如上面的cp1和cp2地址都是 0x0046b01c;
而char* cp2 = "zhou" 这时的cp2地址将是0x0046b04大于原来的地址。所以strcmp的比
较结果才会有这样的定义。
对于c++风格的字符数组形式如果传入的同意数组的元素地址,strcmp将比较两者地址,而
如果传入的不是 ......

c,c++风格字串与strcmp

众所周知,strcmp为字串比较只用,简单的函数并不简单。
下面的代码
int main()
{
      char* cp1 = {'z', 'h', 'a', 'n', 'g'};
      char* cp2 = {'z', 'h', 'a', 'n', 'g'};
      std::cout<<strcmp(cp1, cp2)<<std::endl;
      return 0;
}
看到命名两个字符串相等,但是程序竟然输出-1;
什么原因
其实strcmp在比较过程中如果传入的是c风格的字串像下面这样
char* cp1 = "zhang";
char* cp2 = "zhang";
这是实际上比较的是两个字串的首地址,而这两个字面定义的字串都隐含着类型是const
于是他们在内存中具有相同的地址,所以即使比较两个指针的内容(两个串的地址),也会得到
正确的结果。不过仍然很惊讶,对于不同的字串系统竟然能够准确根据其大小在内存中排列
例如上面的cp1和cp2地址都是 0x0046b01c;
而char* cp2 = "zhou" 这时的cp2地址将是0x0046b04大于原来的地址。所以strcmp的比
较结果才会有这样的定义。
对于c++风格的字符数组形式如果传入的同意数组的元素地址,strcmp将比较两者地址,而
如果传入的不是 ......

Linux c/c++ 开发工具集锦

我之前是一个C程序员,而且是个Windows的程序员,在windows下使用VC6.0/VS2005等microsoft的傻瓜式工具工作,
对于那个vc 6.0/vs2005的快捷操作,debug操作是那么的熟悉,可以说vc
6.0/vs2005是window下开发c/c++最好用的工具了,可以查看调用堆栈,内存变化情况,变量值,另外安装 visual assist
x后让VC看起来是那么的完美。
但是windows下写成代码到了linux下是有问题的,所以建议在vc中将工具-》选项—》制表符—》制表符大小4,插入空格,另外的问题就是

那个回车换行的问题,例如windows下是0d,0a,到了linux下用vi看到的都是^M,给别人带来不便,所以如果提交的服务器是linux,而
你是在windows下开发,可以在svn/cvs中进行设置,就可以自动进行dos2unix的转换,相关的文档可以查看svn/cvs的相关手册,其
中都有这样的设置。
有幸这次我转到了Linux下开发,有幸认识了linux,但是随之而来的就是特别头疼的问题:Linux下使用什么工具进行编码,编
译,debug呢??我感到非常的迷茫,然后就是网上大搜索,看到那么多的网友推荐VIM时,我失望了,特别的失望,然后用VIM敲了一个下午,累的手的
麻了,感到特别的不爽,就像是用左手拿筷子一样,全 ......

Linux c/c++ 开发工具集锦

我之前是一个C程序员,而且是个Windows的程序员,在windows下使用VC6.0/VS2005等microsoft的傻瓜式工具工作,
对于那个vc 6.0/vs2005的快捷操作,debug操作是那么的熟悉,可以说vc
6.0/vs2005是window下开发c/c++最好用的工具了,可以查看调用堆栈,内存变化情况,变量值,另外安装 visual assist
x后让VC看起来是那么的完美。
但是windows下写成代码到了linux下是有问题的,所以建议在vc中将工具-》选项—》制表符—》制表符大小4,插入空格,另外的问题就是

那个回车换行的问题,例如windows下是0d,0a,到了linux下用vi看到的都是^M,给别人带来不便,所以如果提交的服务器是linux,而
你是在windows下开发,可以在svn/cvs中进行设置,就可以自动进行dos2unix的转换,相关的文档可以查看svn/cvs的相关手册,其
中都有这样的设置。
有幸这次我转到了Linux下开发,有幸认识了linux,但是随之而来的就是特别头疼的问题:Linux下使用什么工具进行编码,编
译,debug呢??我感到非常的迷茫,然后就是网上大搜索,看到那么多的网友推荐VIM时,我失望了,特别的失望,然后用VIM敲了一个下午,累的手的
麻了,感到特别的不爽,就像是用左手拿筷子一样,全 ......

Linux c/c++ 开发工具集锦

我之前是一个C程序员,而且是个Windows的程序员,在windows下使用VC6.0/VS2005等microsoft的傻瓜式工具工作,
对于那个vc 6.0/vs2005的快捷操作,debug操作是那么的熟悉,可以说vc
6.0/vs2005是window下开发c/c++最好用的工具了,可以查看调用堆栈,内存变化情况,变量值,另外安装 visual assist
x后让VC看起来是那么的完美。
但是windows下写成代码到了linux下是有问题的,所以建议在vc中将工具-》选项—》制表符—》制表符大小4,插入空格,另外的问题就是

那个回车换行的问题,例如windows下是0d,0a,到了linux下用vi看到的都是^M,给别人带来不便,所以如果提交的服务器是linux,而
你是在windows下开发,可以在svn/cvs中进行设置,就可以自动进行dos2unix的转换,相关的文档可以查看svn/cvs的相关手册,其
中都有这样的设置。
有幸这次我转到了Linux下开发,有幸认识了linux,但是随之而来的就是特别头疼的问题:Linux下使用什么工具进行编码,编
译,debug呢??我感到非常的迷茫,然后就是网上大搜索,看到那么多的网友推荐VIM时,我失望了,特别的失望,然后用VIM敲了一个下午,累的手的
麻了,感到特别的不爽,就像是用左手拿筷子一样,全 ......
总记录数:969; 总页数:162; 每页6 条; 首页 上一页 [68] [69] [70] [71] 72 [73] [74] [75] [76] [77]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号