首页 新闻 会员 周边 捐助

c++ 代码转 c# 代码

0
悬赏园豆:5 [已关闭问题] 关闭于 2013-12-16 10:39
const INT32S TEGUI_MARK[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
 
STDMETHODIMP Arithmetic::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IArithmetic,
};
 
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
 
STDMETHODIMP Arithmetic::TEGUI_FpnToStrEx(float v, SAFEARRAY **outBuff, unsigned char len, unsigned char shift, unsigned char sign,VARIANT_BOOL *result)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
 
INT8U  n=0,i=0;
 
char *pData = NULL;
SafeArrayAccessData(*outBuff,(void **)&pData);
long l = 0, h = 0;
SafeArrayGetLBound(*outBuff,1,&l);
SafeArrayGetUBound(* outBuff,1,&h);//维数索引从1开始
long size=h-l+1;
 
char  temp[128] = {0};
char  *p = &temp[0];
 
INT8U dataLen = 0 ;
 
if(v < 0 )
{
v *= -1;
p[0] = '-';
p++;
dataLen++ ;
}
else
{
if(sign)
{
p[0] = '+' ;
p++;
dataLen++ ;
}
}
n= TEGUI_GetVarBit((INT32S)v);
if (n==len)
{
v += 0.5;
n = TEGUI_GetVarInum((INT32S)v,p);
dataLen += n;
}
if (n<len)
{                                            
i=len-n;
if (i>shift) i=shift;
dataLen += n;
dataLen += i;
dataLen ++  ;
 
v*=TEGUI_MARK[i];
v += 0.5;
n = TEGUI_GetVarInum((INT32S)v,p);
if (n>len)
{
n--;
i--;
p[n]='\0';
}
while (n<=i)
{
TEGUI_StrInsertChar(p,'0',0);
n++;
}
if (i) TEGUI_StrInsertChar(p,'.',n-i);
}
if (n>len)
{
for (i=0;i<len;i++)
p[i] = '9';
p[i] = '\0';
dataLen += i ;
}
ASSERT(dataLen<size);
for (long t=0;t<dataLen;t++)
{
HRESULT hr = SafeArrayPutElement(*outBuff,&t,&temp[t]);//数组赋值.
}
SafeArrayUnaccessData(*outBuff);
return S_OK;
}
 
INT8U Arithmetic::TEGUI_GetVarBit(INT32S v)
{
INT8U i=0;
if (v<0) v *= -1;
// do{i++;}while(v>=TEGUI_MARK[i]);
for (i=1;i<10;i++)
{
if (TEGUI_MARK[i]>v)
break;
}
return i;
}
INT8U Arithmetic::TEGUI_GetVarInum(INT32U v, char s[])
{
char str[15];
INT8U k=0,i;
if (v)
{
while (v)
{
str[k] = v % 10 + '0';
k++;
v -= v % 10;
v /= 10;
}
i=0;
while (k)
{
s[i] = str[k-1];
i++;
k--;
}
s[i]='\0';
}
else
{
s[0]='0';
s[1]='\0';
i=1;
}
return i;
 
}
char *Arithmetic::TEGUI_StrInsertChar(char str[],char ch, INT8U off)
{
INT8U i;
char t1,t2;
t1 = str[off];
str[off] =ch;
for (i=off+1;t1!='\0';i++)
{
t2 = str[i];
str[i] = t1;
t1 = t2;
}
str[i] = t1;
return str;
}
鲤伴先生的主页 鲤伴先生 | 初学一级 | 园豆:9
提问于:2013-05-16 21:58
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册