本文介绍了C ++程序(32位)转换为C ++程序(64位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个名为SBLIB DLL Ver 1.0 for Win32的c ++程序 我试图用VS 2008转换它,但是没有工作。 我有以下代码,任何人都可以帮助我。 我想在64位操作系统中使用这个DLL 。目前这个dll可以在所有32位操作系统中工作 源文件如下: === =================== SBLIB.DEF ---- ------ ; ----------------------------------- - ; SBLIB.DEF模块定义文件 ; ----------------------------------- - LIBRARY SBLIBVB32 描述'SBLIBVB32 DLL' ; EXETYPE WINDOWS ; STUB'WINSTUB.EXE' 代码PRELOAD可移动可丢弃 数据预付可移动单个 HEAPSIZE 2048 出口广告 hstad uruu chkday gttime sttime mkttime itvday itvhr itvmin itvsec endmon dyweek adtsy sytad todday todhr todmin todsec localttime ad2to4 ad4to2 SBLIB.C -------- / * * Win32的SBLIB DLL Ver 1.0 * * / #include< windows.h> #include< stdio.h> #include< sys\types.h> #include< time.h> #include< string.h> #includesblib.h int FAR PASCAL adths(int ad,int FAR * hs) { if(ad< 0 ||广告> 99) 返回-1; if(ad> = 0&& ad< = 88) ad + = 100; * hs = ad - 88; 返回0; } int FAR PASCAL hstad(int hs,int FAR * ad) { if(hs< = 0 || hs > 100) 返回-1; * ad = hs + 88; if(* ad> = 100)* ad%= 100; 返回0; } int FAR PASCAL uruu(int year) { int rtn = 0; if(year< 0) 返回-1; if(((年%4 == 0)& &(年%100!= 0))||(年%400 == 0)) rtn = 1; 返回rtn; } int FAR PASCAL chkday(TTIME FAR * ttime) { int year; if(ttime-> year< 0 || ttime-> year> 99) return(-1); if(ttime-> mon< 1 || ttime-> mon> 12) 返回(-2); if(ttime-> day< 1 || ttime-> day> 31) 返回(-3); 年= ad2to4(ttime->年); 开关(ttime-> mon){ 案例1: 案例3: 案例5 : 案例7: 案例8: 案例10: 案例12: 休息; 案例4: 案例6: 案例9: 案例11: if(ttime-> day> 30){ return(-3); } 休息; 案例2: if(uruu(year)== 1){ if(ttime-> day> 29 ){ 返回(-3); } } 其他{ if(ttime-> day> 28){ 返回(-3); } } 休息; 默认: 返回(-3); } if(ttime-> hour< 0 || tti me->小时> 23){ 返回(-4); } if(ttime-> min< ; 0 || ttime-> min> 59){ 返回(-5); } if(ttime-> sec< 0 || ttime-> sec> 59){ return(-6); } 返回(0); } int FAR PASCAL gttime(TTIME FAR * ttime) { time_t t; struct tm * tm; _tzset(); 时间(& t); tm = localtime( & t); ttime-> year = ad4to2(tm-> tm_year); ttime-> mon = tm-> tm_mon + 1; ttime-> day = tm-> tm_mday; ttime-> hour = tm-> tm_hour; ttime-> min = tm-> tm_min; ttime-> sec = tm-> tm_sec; 返回0; } int FAR PASCAL sttime(TTIME FAR * ttime) { SYSTEMTIME SystemTime; _tzset(); if(chkday(ttime)) return(-1); SystemTime.wYear =(WORD)ad2to4(ttime-> year); SystemTime.wMonth =(WORD)ttime-> mon; SystemTime.wDay =(WORD)ttime-> day; SystemTime.wHour =(WORD)ttime-> hour; SystemTime.wMinute =(WORD)ttime-> min; SystemTime.wSecond =(WORD)ttime-> sec; SystemTime.wMilliseconds = 0 ; if(SetLocalTime(& SystemTime)!= TRUE) return(-1); 返回(0); } int FAR PASCAL itvday(TTIME FAR * time1,TTIME FAR * time2,long FAR * day) { time_t td1,td2; double ans; if(chkday(time1)) 返回(-1); if(chkday(time2)) return(-2) ; td1 = mkttime(time1); td2 = mkttime(time2); ans = difftime(td2,td1); * day =(long)(ans / 86400); 返回(0); } int FAR PASCAL itvhr (TTIME FAR * time1,TTIME FAR * time2,long FAR * hr) { time_t td1,td2; long ans; if(chkday(time1)) return(-1 ); if(chkday(time2)) return(-2); td1 = mkttime(time1); td2 = mkttime(time2); ans =(长)difftime(td2,td1); * hr =(长)(ans / 3600); 返回(0); } int FAR PASCAL itvmin(TTIME FAR * time1,TTIME FAR * time2,long FAR * min) { time_t td1,td2; 长ans; 如果(chkday(time1)) 返回( - 1); if(chkday(time2)) return(-2); td1 = mkttime(time1); td2 = mkttime(time2); ans =(长)difftime(td2,td1); * min =(长)(ans / 60); 返回(0); } int FAR PASCAL itvsec(TTIME FAR * time1,TTIME FAR * time2,long FAR * sec) { time_t td1,td2; long ans; if(chkday(time1)) return(-1); if(chkday(time2)) 返回(-2); td1 = mkttime (time1); td2 = mkttime(time2); ans =(长)difftime(td2,td1); * sec =(长)ans; 返回(0); } time_t FAR PASCAL mkttime(TTIME FAR * ttime) { struct tm tm; time_t mktime(); tm.tm_year = ad2to4(ttime-> year) - 1900; tm.tm_mon = ttime-> mon - 1; tm.tm_mday = ttime-> day; tm.tm_hour = ttime-> hour; tm.tm_min = ttime-> min; tm.tm_sec = ttime-> sec; tm.tm_wday = 0; tm.tm_yday = 0; tm.tm_isdst = -1; 返回(mktime(& tm)); } int FAR PASCAL endmon(TTIME FAR * ttime,int FAR * mday) { int year; if(ttime-> year< 0 || ttime-> year> 99) return(-1); if(ttime-> mon< 1 || ttime-> mon> 12) return(-2); year = ad2to4(ttime-> year); switch(ttime-> mon) { 案例1: 案例3: 案例5: 案例7: 案例8: 案例10: 案例12: * mday = 31; 休息; 案例4: 案例6: 案例9: 案例11: * mday = 30; 休息; 案例2: if(uruu(year)== 1) * mday = 29; else * mday = 28; 休息; 默认: 返回(-2); } 返回(0); } int FAR PASCAL dyweek(TTIME FAR * ttime,int FAR * wday) { struct tm tm; int rtc; rtc = chkday(ttime); if((rtc == -1)|| (rtc == -2)|| (rtc == -3)) 返回(-1); tm.tm_year = ad2to4(ttime-> year) - 1900; tm.tm_mon = ttime-> mon - 1; tm.tm_mday = ttime-> day; tm .tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm .tm_wday = 0; tm.tm_yday = 0; tm.tm_isdst = -1; mktime(& tm); * wday = tm.tm_wday + 1; 返回(0); } int FAR PASCAL adtsy(int ad,int FAR * sy) { if(ad< 26 || ad> ; 89) 返回(-1); * sy = ad - 25; 返回(0); } int FAR PASCAL sytad(int sy,int FAR * ad) 返回(-1); * ad = sy + 25; 返回(0); } int FAR PASCAL todday(TTIME FAR * time1,漫长的一天,TTIME FAR * time2) { time_t t1; if(chkday(time1)){ return(-1); } t1 = mkttime(time1); t1 + = day * 86400; localttime(t1,time2); 返回(0); } int FAR PASCAL todhr(TTIME FAR * time1,long hr,TTIME FAR * time2) { time_t t1; if(chkday(time1)){ return(-1); } t1 = mkttime(time1 ); t1 + = hr * 3600; localttime(t1,time2); 返回(0); } int FAR PASCAL todmin(TTIME FAR * time1,long min,TTIME FAR * time2) { time_t t1; if(chkday(time1)){ return(-1); } t1 = mkttime(time1 ); t1 + = min * 60; localttime(t1,time2); 返回(0); } int FAR PASCAL todsec(TTIME FAR * time1,long sec,TTIME FAR * time2) { time_t t1; if(chkday(time1)){ return(-1); } t1 = mkttime(time1); t1 + = sec; localttime (t1,time2); 返回(0); } 无法FAR PASCAL localttime(time_t t,TTIME FAR * ttime) { struct tm * tm; time_t ts; _tzset(); ts = t; tm = localtime(& ts); ttime-> year = ad4to2(tm-> tm_year); ttime-> mon = tm-> tm_mon + 1; ttime-> day = tm-> tm_mday; ttime->小时= tm-> tm_hour; ttime-> min = tm-> tm_min; ttime-> sec = tm-> tm_sec; } int FAR PASCAL ad2to4(int ad2) { if((ad2> = 70)&&(ad2< = 99)) return(ad2 + 1900) ); 其他 返回(ad2 + 2000); } int FAR PASCAL ad4to2(int ad4) { return(ad4%100); } 资源文件如下 ====================== ==== // {{NO_DEPENDENCIES}} // Microsoft Developer Studio生成包含文件。 //由Script1使用。 rc // //新物品的下一个默认值 // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 #define _APS_NEXT_COMMAND_VALUE 40001 # define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif 头文件如下: ===================== / * * SBLIB HEADDER文件 * * * / #include< sys types.h => typedef struct { 短年; 短周期; 短一天; 短小时; 短分钟; 短秒; 短暂时间; 短福; } TTIME; time_t FAR PASCAL mkttime(TTIME FAR *); int FAR PASCAL ad2to4(int); int FAR PASCAL ad4to2(int); void FAR PASCAL localttime(time_t,TTIME FAR *); int FAR PASCAL dyweek(TTIME FAR *,int FAR *); 我尝试了什么: 我试图加载64位VS2008中的copiler并尝试编译它。 编译时没有错误,但在程序中引用时,它不能被使用。I have a c++ program named SBLIB DLL Ver 1.0 for Win32I would like to convert it to 64 bit.I tried to convert it using VS 2008, but not working.I have the below codes, can any one help me.I want to use this DLL in 64 bit OS. Currently this dll can work in all 32 bit OSSource files as below:======================SBLIB.DEF----------;------------------------------------; SBLIB.DEF module definition file;------------------------------------LIBRARYSBLIBVB32DESCRIPTION'SBLIBVB32 DLL';EXETYPE WINDOWS;STUB 'WINSTUB.EXE'CODE PRELOAD MOVEABLE DISCARDABLEDATA PRELOAD MOVEABLE SINGLEHEAPSIZE 2048EXPORTSadthshstaduruuchkdaygttimesttimemkttimeitvdayitvhritvminitvsecendmondyweekadtsysytadtoddaytodhrtodmintodseclocalttimead2to4ad4to2SBLIB.C--------/* * SBLIB DLL Ver 1.0 for Win32 * */#include <windows.h>#include <stdio.h>#include <sys\types.h>#include <time.h>#include <string.h>#include "sblib.h"int FAR PASCAL adths( int ad, int FAR *hs ){if( ad < 0 || ad > 99 )return -1 ;if( ad >=0 && ad <= 88 )ad += 100 ;*hs = ad - 88 ;return 0 ;}int FAR PASCAL hstad( int hs, int FAR *ad ){if( hs <= 0 || hs > 100 )return -1 ;*ad = hs + 88 ;if( *ad >= 100 ) *ad %= 100 ;return 0 ;}int FAR PASCALuruu( int year ){intrtn = 0;if( year < 0 )return -1 ;if( ( ( year%4 == 0 ) && ( year%100 != 0 ) ) || ( year%400 == 0 ) )rtn = 1 ;return rtn ;}int FAR PASCALchkday( TTIME FAR *ttime ){intyear;if( ttime->year < 0 || ttime->year > 99 )return( -1 ) ;if( ttime->mon < 1 || ttime->mon > 12 )return( -2 ) ;if( ttime->day < 1 || ttime->day > 31 )return( -3 ) ;year = ad2to4(ttime->year);switch( ttime->mon ) { case 1 : case 3 : case 5 : case 7 : case 8 : case 10 : case 12 :break ; case 4 : case 6 : case 9 : case 11 :if( ttime->day > 30 ) {return( -3 ) ;}break ; case 2 :if( uruu( year ) == 1 ) {if( ttime->day > 29 ) {return( -3 ) ;}}else {if( ttime->day > 28 ) {return( -3 ) ;}}break ; default :return( -3 ) ;}if( ttime->hour < 0 || ttime->hour > 23 ) {return( -4 ) ;}if( ttime->min < 0 || ttime->min > 59 ) {return( -5 ) ;}if( ttime->sec < 0 || ttime->sec > 59 ) {return( -6 ) ;}return( 0 ) ;}int FAR PASCALgttime( TTIME FAR *ttime ){time_tt;structtm*tm; _tzset() ;time( &t ) ;tm = localtime( &t ) ;ttime->year = ad4to2(tm->tm_year);ttime->mon = tm->tm_mon + 1 ;ttime->day = tm->tm_mday ;ttime->hour = tm->tm_hour ;ttime->min = tm->tm_min ;ttime->sec = tm->tm_sec ;return 0 ;}int FAR PASCALsttime( TTIME FAR *ttime ){SYSTEMTIMESystemTime; _tzset() ;if( chkday( ttime ) )return( -1 ) ;SystemTime.wYear = (WORD)ad2to4(ttime->year);SystemTime.wMonth = (WORD)ttime->mon;SystemTime.wDay = (WORD)ttime->day;SystemTime.wHour = (WORD)ttime->hour;SystemTime.wMinute = (WORD)ttime->min ;SystemTime.wSecond = (WORD)ttime->sec ;SystemTime.wMilliseconds = 0;if( SetLocalTime( &SystemTime ) != TRUE )return( -1 );return( 0 ) ;}int FAR PASCALitvday( TTIME FAR *time1, TTIME FAR *time2, long FAR *day ){time_ttd1, td2;doubleans;if( chkday( time1 ) )return( -1 );if( chkday( time2 ) )return( -2 );td1 = mkttime( time1 );td2 = mkttime( time2 );ans = difftime( td2, td1);*day = (long) ( ans / 86400) ;return( 0 ) ;}int FAR PASCALitvhr( TTIME FAR *time1, TTIME FAR *time2, long FAR *hr ){time_ttd1, td2;longans;if( chkday( time1 ) )return( -1 );if( chkday( time2 ) )return( -2 );td1 = mkttime( time1 );td2 = mkttime( time2 );ans = (long)difftime( td2, td1);*hr = (long) ( ans / 3600 );return( 0 ) ;}int FAR PASCALitvmin( TTIME FAR *time1, TTIME FAR *time2, long FAR *min ){time_ttd1, td2;longans;if( chkday( time1 ) )return( -1 );if( chkday( time2 ) )return( -2 );td1 = mkttime( time1 );td2 = mkttime( time2 );ans = (long)difftime( td2, td1);*min = (long)( ans / 60 );return( 0 ) ;}int FAR PASCALitvsec( TTIME FAR *time1, TTIME FAR *time2, long FAR *sec ){time_ttd1, td2;longans;if( chkday( time1 ) )return( -1 );if( chkday( time2 ) )return( -2 );td1 = mkttime( time1 );td2 = mkttime( time2 );ans = (long)difftime( td2, td1);*sec = (long)ans;return( 0 );}time_t FAR PASCALmkttime( TTIME FAR *ttime ){structtmtm;time_tmktime();tm.tm_year = ad2to4(ttime->year) - 1900;tm.tm_mon = ttime->mon - 1;tm.tm_mday = ttime->day;tm.tm_hour = ttime->hour;tm.tm_min = ttime->min;tm.tm_sec = ttime->sec;tm.tm_wday = 0;tm.tm_yday = 0;tm.tm_isdst= -1;return( mktime( &tm ) );}int FAR PASCALendmon( TTIME FAR *ttime, int FAR *mday ){intyear ;if( ttime->year < 0 || ttime->year > 99 )return( -1 ) ;if( ttime->mon < 1 || ttime->mon > 12 )return( -2 ) ;year = ad2to4(ttime->year);switch( ttime->mon ){case 1 :case 3 :case 5 :case 7 :case 8 :case 10 :case 12 :*mday = 31 ;break ;case 4 :case 6 :case 9 :case 11 :*mday = 30 ;break ;case 2 :if( uruu( year ) == 1 )*mday = 29 ;else*mday = 28 ;break ;default :return( -2 ) ;}return( 0 ) ;}int FAR PASCALdyweek( TTIME FAR *ttime, int FAR *wday ){struct tmtm;intrtc ;rtc = chkday( ttime ) ;if( ( rtc == -1 ) || ( rtc == -2 ) || ( rtc == -3 ) )return( -1 ) ;tm.tm_year = ad2to4(ttime->year) - 1900;tm.tm_mon = ttime->mon - 1;tm.tm_mday = ttime->day;tm.tm_hour = 0;tm.tm_min = 0;tm.tm_sec = 0;tm.tm_wday = 0;tm.tm_yday = 0;tm.tm_isdst= -1;mktime( &tm );*wday = tm.tm_wday + 1;return( 0 );}int FAR PASCALadtsy( int ad, int FAR *sy ){if( ad < 26 || ad > 89 )return( -1 ) ;*sy = ad - 25 ;return( 0 ) ;}int FAR PASCALsytad( int sy, int FAR *ad ){if( sy < 1 || sy > 64 )return( -1 ) ;*ad = sy + 25 ;return( 0 ) ;}int FAR PASCALtodday( TTIME FAR *time1, long day, TTIME FAR *time2 ){time_tt1;if( chkday( time1 ) ) {return( -1 );}t1 = mkttime( time1 );t1 += day * 86400;localttime( t1, time2 );return( 0 );}int FAR PASCALtodhr( TTIME FAR *time1, long hr, TTIME FAR *time2 ){time_tt1;if( chkday( time1 ) ) {return( -1 );}t1 = mkttime( time1 );t1 += hr * 3600;localttime( t1, time2 );return( 0 );}int FAR PASCALtodmin( TTIME FAR *time1, long min, TTIME FAR *time2 ){time_tt1;if( chkday( time1 ) ) {return( -1 );}t1 = mkttime( time1 );t1 += min * 60;localttime( t1, time2 );return( 0 );}int FAR PASCALtodsec( TTIME FAR *time1, long sec, TTIME FAR *time2 ){time_tt1;if( chkday( time1 ) ) {return( -1 );}t1 = mkttime( time1 );t1 += sec;localttime( t1, time2 );return( 0 );}void FAR PASCAL localttime( time_t t, TTIME FAR *ttime ){structtm*tm;time_tts; _tzset() ;ts = t;tm = localtime( &ts ) ;ttime->year = ad4to2(tm->tm_year);ttime->mon = tm->tm_mon + 1 ;ttime->day = tm->tm_mday ;ttime->hour = tm->tm_hour ;ttime->min = tm->tm_min ;ttime->sec = tm->tm_sec ;}int FAR PASCALad2to4( int ad2 ){if( ( ad2 >= 70 ) && ( ad2 <= 99 ) )return( ad2 + 1900);elsereturn( ad2 + 2000);}int FAR PASCALad4to2( int ad4 ){return( ad4 % 100);}Resource files as below==========================//{{NO_DEPENDENCIES}}// Microsoft Developer Studio generated include file.// Used by Script1.rc//// Next default values for new objects//#ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE 101#define _APS_NEXT_COMMAND_VALUE 40001#define _APS_NEXT_CONTROL_VALUE 1000#define _APS_NEXT_SYMED_VALUE 101#endif#endifHeader files as below:=====================/* *SBLIB HEADDER FILE * * */#include <sys types.h="">typedefstruct {shortyear;shortmon;shortday;shorthour;shortmin;shortsec;shortmsec;shortfu;} TTIME;time_tFAR PASCALmkttime( TTIME FAR * );intFAR PASCALad2to4( int );intFAR PASCALad4to2( int );voidFAR PASCALlocalttime( time_t, TTIME FAR *);int FAR PASCALdyweek( TTIME FAR *, int FAR *);What I have tried:I tried to load 64 bit copiler in VS2008 and tried to compile it.It compiles with no errors, but when referred in program, it cannot be used.推荐答案 15秒的谷歌发现了这一点:一般移植指南Microsoft Docs [ ^ ] 其中讨论了将32位Windows代码转换为64位的问题。另请参阅屏幕左侧菜单中的主题。15 seconds of Google found this: General Porting Guidelines | Microsoft Docs[^]Which discusses issues in conversion of 32-bit Windows code to 64-bit. See also the subjects in the menu on the left of the screen. 这篇关于C ++程序(32位)转换为C ++程序(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 16:24