|
Thank you for the reply prasad_som.
Yes, I want to rename the file ... well kinda, the thing is I wrote a tcp/ip client - server. And the client sends a file to the server, but the server must change the extension of the file when the file transfer begins and change it back to the original extension. The thing is all the code is dynamic and file paths & extension can change... tricky ....
Thanx again
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
hmmm.
You may like to have look at this for parsing file name
basic_string::rfind ,CString::ReverseFind . Look to lst '.' character, and change it to rquired.
|
|
|
|
|
Thank you very much ... I'll check it out...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
prasad_som wrote: Look to lst '.' character, and change it to rquired.
Or use PathFindExtension() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Or use PathFindExtension().
Very true. My 5.
|
|
|
|
|
« Programm3r » wrote: Is it possible to use the strncpy() function to achive the following:
FileName1.txt to FileName1.abc
Why not just use PathRenameExtension() ?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I wand to read file form end to the start of the file...
byte by byte...
can anyone suggest me or provide me any sample code that helps me...??????
thanks in advance...
Savcejana Sukinobavanthu
Ashok.
|
|
|
|
|
You could do it with a for loop, find the length of the file in bytes (using a while loop or otherwise)
then do a for loop but backwards
for(int i=FileLength; i>=0; i -=1) {
//Read the file i number of bytes
}
|
|
|
|
|
Why do you need to do this? I would suggest reading the file into a buffer, and then reversing that buffer. It'll be much faster this way.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
or reading the file and inserting in the buffer at the beginning instead of at the end.
|
|
|
|
|
Maximilien wrote: or reading the file and inserting in the buffer at the beginning...
Which is how files are normally read.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I don't know, if I have to read a file in order, I will read a line ( for example, a text file ) and add the newly read line at the end of my "buffer".
if I want to read the file in reverse order, I might read the file in order and then sort internally what I have read, or try to read the file in reverse (from the end ) and add to the buffer at the end.
|
|
|
|
|
Thismay not be the proper forum for this posting so I appoligise in advance if I have got it wrong, but i am hoping that someone can help me with my problem.
The problem is that when using IM with PDFMDD11.lib (thrid party Libraries) and third party lib under VS2005 and I then try to link to the StaticMTDLL IM Libraries I am recieving link errors indicating objects already defined.
I believe that the problem is a conflict of some kind between the PDF image libraries for reading/writing TIFF, PNG, and JPEG files and the Imagemagic Libraries. Can anyone help me put with this and provide a solution if possable.
The errors read.
>log4cppD.lib(CategoryStream.obj) : warning LNK4075: ignoring
'/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>CORE_DB_magick_.lib(nt-base.obj) : error LNK2005: _DllMain@12 already
defined in MSVCRTD.lib(dllmain.obj)
1>CORE_DB_tiff_.lib(tif_error.obj) : error LNK2005: _TIFFSetErrorHandler
already defined in pdfMDD11.lib(tif_error.obj)
1>CORE_DB_tiff_.lib(tif_error.obj) : error LNK2005: _TIFFError already
defined in pdfMDD11.lib(tif_error.obj)
1>CORE_DB_tiff_.lib(tif_warning.obj) : error LNK2005: _TIFFSetWarningHandler
already defined in pdfMDD11.lib(tif_warning.obj)
1>CORE_DB_tiff_.lib(tif_warning.obj) : error LNK2005: _TIFFWarning already
defined in pdfMDD11.lib(tif_warning.obj)
1>CORE_DB_png_.lib(pngvcrd.obj) : error LNK2005: _png_mmx_support already
defined in pdfMDD11.lib(png.obj)
1>..\..\output\Debug\Controller_win.dll : fatal error LNK1169: one or more
multiply defined symbols found
Options that I have tried include the /FORCE switch usage on the Linker Command line. Any solution ideas would be welcomed
Many thanks
Nigel
|
|
|
|
|
hi
how to show percentage completion on progress bar?
thanks
|
|
|
|
|
Maybe you should add a label control (CStatic ) near your progress bar, and set its text programmatically? Something like this:
CString s;
s.Format(_T("%i%%"), m_cMyProgressBar.GetPos());
m_cMyLabel.SetWindowText(s);
I hope this helps.
|
|
|
|
|
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I saw examples on the codeproject about it did you search on codeproject
|
|
|
|
|
How can I change IP address of my system programmatically ?
Thanks .
|
|
|
|
|
the IPM_SETADDRESS message
Tom
|
|
|
|
|
No sorry, Ihavn't woken up this morning yet, I was thinking of the IP control Sorry
Tom
|
|
|
|
|
Hi,
try to check this AddIPAddress[^], and analyze the sample
And other view on this issue (I'm not sure if recommended by MS) Changing IPADDRESS[^]
-----------
Mila
|
|
|
|
|
Here is another way of doing it, Sorry about earlier
<br />
**************************************************************************<br />
<br />
#define POLARITY<br />
#define _WIN32_DCOM<br />
<br />
#include <br />
#include <br />
using namespace std;<br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
<br />
#include <br />
<br />
int WMIEnableStatic()<br />
{<br />
IWbemLocator *pLocator = NULL;<br />
IWbemServices *pNamespace = 0;<br />
IWbemClassObject * pClass = NULL;<br />
IWbemClassObject * pOutInst = NULL;<br />
IWbemClassObject * pInClass = NULL;<br />
IWbemClassObject * pInInst = NULL;<br />
<br />
BSTR path = SysAllocString(L"root\\cimv2");<br />
BSTR ClassPath = SysAllocString(L"Win32_NetWorkAdapterConfiguration");<br />
BSTR InstancePath =<br />
SysAllocString(L"Win32_NetWorkAdapterConfiguration.Index='1'");<br />
BSTR MethodName = SysAllocString(L"EnableStatic");<br />
BSTR ArgName1 = SysAllocString(L"IPAddress");<br />
BSTR ArgName2 = SysAllocString(L"SubNetMask");<br />
<br />
<br />
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); <br />
<br />
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,<br />
RPC_C_AUTHN_LEVEL_CONNECT, <br />
RPC_C_IMP_LEVEL_IMPERSONATE, <br />
NULL, EOAC_NONE, 0<br />
);<br />
<br />
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,<br />
IID_IWbemLocator, (LPVOID *) &pLocator);<br />
<br />
hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL, NULL,<br />
&pNamespace);<br />
<br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
cout << "Connected to WMI" << endl;<br />
<br />
hr = CoSetProxyBlanket(pNamespace,<br />
RPC_C_AUTHN_WINNT,<br />
RPC_C_AUTHZ_NONE,<br />
NULL,<br />
RPC_C_AUTHN_LEVEL_CALL,<br />
RPC_C_IMP_LEVEL_IMPERSONATE,<br />
NULL,<br />
EOAC_NONE<br />
);<br />
<br />
<br />
<br />
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);<br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
<br />
<br />
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL); <br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
hr = pInClass->SpawnInstance(0, &pInInst);<br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
<br />
BSTR ip;<br />
ip = SysAllocString(L"10.0.0.3");<br />
<br />
BSTR mask;<br />
mask = SysAllocString(L"255.255.255.0");<br />
<br />
long index[]={0};<br />
<br />
SAFEARRAY *ip_list;<br />
ip_list = SafeArrayCreateVector(VT_BSTR,0,1);<br />
SafeArrayPutElement(ip_list,index,ip);<br />
<br />
SAFEARRAY *mask_list;<br />
mask_list = SafeArrayCreateVector(VT_BSTR,0,1);<br />
SafeArrayPutElement(mask_list,index,mask);<br />
<br />
VARIANT arg1;<br />
arg1.vt = VT_ARRAY|VT_BSTR;<br />
arg1.parray = ip_list;<br />
hr = pInInst->Put(ArgName1, 0, &arg1, 0);<br />
<br />
VARIANT arg2;<br />
arg2.vt = VT_ARRAY|VT_BSTR;;<br />
arg2.parray = mask_list;<br />
hr = pInInst->Put(ArgName2, 0, &arg2, 0);<br />
<br />
<br />
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL, pInInst,<br />
&pOutInst, NULL);<br />
if(hr != WBEM_S_NO_ERROR){<br />
cout << "ExecMethod failed " << hr;<br />
return 1;<br />
}<br />
<br />
<br />
VARIANT ret_value;<br />
BSTR strReturnValue = SysAllocString(L"ReturnValue");<br />
hr = pOutInst->Get(strReturnValue, 0, &ret_value, 0, 0);<br />
long ret = V_I4(&ret_value);<br />
if(ret != 0) {<br />
cout << "EnableStatic failed with return code = " << ret;<br />
}else{<br />
cout << "EnableStatic succeeded" << endl;<br />
}<br />
<br />
<br />
SysFreeString(strReturnValue);<br />
VariantClear(&ret_value);<br />
SysFreeString(ip);<br />
SysFreeString(mask);<br />
SafeArrayDestroy(ip_list);<br />
SafeArrayDestroy(mask_list);<br />
VariantClear(&arg1);<br />
VariantClear(&arg2);<br />
<br />
SysFreeString(path);<br />
SysFreeString(ClassPath);<br />
SysFreeString(InstancePath);<br />
SysFreeString(MethodName);<br />
SysFreeString(ArgName1);<br />
SysFreeString(ArgName2);<br />
<br />
pClass->Release();<br />
pInInst->Release();<br />
pInClass->Release();<br />
pOutInst->Release();<br />
pLocator->Release();<br />
pNamespace->Release();<br />
CoUninitialize();<br />
return 0;<br />
}
Hope this helps a bit more
Tom
|
|
|
|
|
edit you post and use the <pre></pre> tags around your code.
thanks you
|
|
|
|
|
As you prefer
**************************************************************************
#define POLARITY
#define _WIN32_DCOM
#include
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
int WMIEnableStatic()
{
IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = 0;
IWbemClassObject * pClass = NULL;
IWbemClassObject * pOutInst = NULL;
IWbemClassObject * pInClass = NULL;
IWbemClassObject * pInInst = NULL;
BSTR path = SysAllocString(L"root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetWorkAdapterConfiguration");
BSTR InstancePath =
SysAllocString(L"Win32_NetWorkAdapterConfiguration.Index='1'");
BSTR MethodName = SysAllocString(L"EnableStatic");
BSTR ArgName1 = SysAllocString(L"IPAddress");
BSTR ArgName2 = SysAllocString(L"SubNetMask");
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0
);
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLocator);
hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
if(hr != WBEM_S_NO_ERROR)
return 1;
cout << "Connected to WMI" << endl;
hr = CoSetProxyBlanket(pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
if(hr != WBEM_S_NO_ERROR)
return 1;
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL);
if(hr != WBEM_S_NO_ERROR)
return 1;
hr = pInClass->SpawnInstance(0, &pInInst);
if(hr != WBEM_S_NO_ERROR)
return 1;
BSTR ip;
ip = SysAllocString(L"10.0.0.3");
BSTR mask;
mask = SysAllocString(L"255.255.255.0");
long index[]={0};
SAFEARRAY *ip_list;
ip_list = SafeArrayCreateVector(VT_BSTR,0,1);
SafeArrayPutElement(ip_list,index,ip);
SAFEARRAY *mask_list;
mask_list = SafeArrayCreateVector(VT_BSTR,0,1);
SafeArrayPutElement(mask_list,index,mask);
VARIANT arg1;
arg1.vt = VT_ARRAY|VT_BSTR;
arg1.parray = ip_list;
hr = pInInst->Put(ArgName1, 0, &arg1, 0);
VARIANT arg2;
arg2.vt = VT_ARRAY|VT_BSTR;;
arg2.parray = mask_list;
hr = pInInst->Put(ArgName2, 0, &arg2, 0);
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL, pInInst,
&pOutInst, NULL);
if(hr != WBEM_S_NO_ERROR){
cout << "ExecMethod failed " << hr;
return 1;
}
VARIANT ret_value;
BSTR strReturnValue = SysAllocString(L"ReturnValue");
hr = pOutInst->Get(strReturnValue, 0, &ret_value, 0, 0);
long ret = V_I4(&ret_value);
if(ret != 0) {
cout << "EnableStatic failed with return code = " << ret;
}else{
cout << "EnableStatic succeeded" << endl;
}
SysFreeString(strReturnValue);
VariantClear(&ret_value);
SysFreeString(ip);
SysFreeString(mask);
SafeArrayDestroy(ip_list);
SafeArrayDestroy(mask_list);
VariantClear(&arg1);
VariantClear(&arg2);
SysFreeString(path);
SysFreeString(ClassPath);
SysFreeString(InstancePath);
SysFreeString(MethodName);
SysFreeString(ArgName1);
SysFreeString(ArgName2);
pClass->Release();
pInInst->Release();
pInClass->Release();
pOutInst->Release();
pLocator->Release();
pNamespace->Release();
CoUninitialize();
return 0;
}
I've never used these before. What's the deal? the code seemed to apear as it should
tom
|
|
|
|
|
Why did you suggest I did that?
It looks terrible, all the formatting has gone!
Tom
|
|
|
|
|