程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> 關於C >> C語言調用powerBuilder開發數據庫

C語言調用powerBuilder開發數據庫

編輯:關於C

C語言編寫數據庫系統不方便,可以使用權PBNI接口來操作powerbuilder,開發數據庫輕松。

[cpp]
// pbtest.cpp : Defines the entry point for the console application. 
// 
 
#include "stdafx.h" 
#include "stdio.h" 
 
typedef PBXEXPORT PBXRESULT (*P_PB_GetVM)(IPB_VM** vm); 
 
int main(int argc, char* argv[]) 

 IPB_Session* session;    
 IPB_VM* pbvm = NULL;    //Load the PowerBuilder VM module    
 HINSTANCE hinst = LoadLibrary("pbvm90.dll");    
  
 if ( hinst== NULL)  
  return 0;    
 fprintf(stderr, "Loaded PBVM successfully\n"); 
  
 P_PB_GetVM getvm = (P_PB_GetVM)GetProcAddress      (hinst,"PB_GetVM");   
 if (getvm == NULL) return 0;     
 getvm(&pbvm);   
 if (pbvm == NULL) return 0; 
  
 LPCTSTR LibList[] = {"genapp.dll"};    
 if ( pbvm->CreateSession("genapp", LibList, 1,      &session) != PBX_OK )   
 {     
  fprintf(stderr, "Error in CreateSession\n");     
  return 1;   
 }  
 fprintf(stderr, "Created session successfully\n"); 
  
 pbgroup group = session->FindGroup("nvo_mult",      pbgroup_userobject);   
 if (group == NULL)  
  return 0;      // Now find the class nvo_mult in the group    
  
 pbclass cls = session->FindClass(group,"nvo_mult");   
 if (cls == NULL) 
  return 0;      // Create an instance of the PowerBuilder object   
 pbobject pbobj = session->NewObject(cls); 
  
 PBCallInfo ci;     // To call the class member function f_mult,    // pass its signature as the last argument   // to GetMethodID     
  
 pbmethodID mid = session->GetMethodID(cls, "f_mult",      PBRT_FUNCTION, "III");    // Initialize call info structure based on method ID   
 session->InitCallInfo(cls, mid, &ci); 
  
 ci.pArgs-> GetAt(0)->SetInt(10);   
 ci.pArgs-> GetAt(1)->SetInt(20); 
  
 try   {       
  session->InvokeObjectFunction(pbobj, mid, &ci);       // Was PB exception thrown?      
  if (session->HasExceptionThrown())       
  {         // Handle PB exception         
   session->ClearException();      
  }    
 }   catch (...)   
 {      // Handle C++ exception   
 }    // Get the return value and print it to the console   
 pbint ret = ci.returnValue->GetInt();    
 fprintf(stderr, "The product of 123 and 45 is %i\n",    ret); 
  
 session->FreeCallInfo(&ci);   
 //delete &ci;    // Release session    
 session->Release();   
  
  
 return 0; 
 FreeLibrary(hinst); 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved