|
I have an existing C++ project, Visual studio 9, running on Windows 7.
I want to write a non-managed piece of code to open a database.
First time round the database won't exist, so I want an error so that I can then run some code to create it.
So far:
DAO doesn't work (it used to in another project)...
m_pDB = new CDaoDatabase(NULL);// use a temporary workspace
// try to open it, not exclusive, not read only the connect arguements left blank (default)
// failure throws an exception (not nice really - rather it returned a false
// fails if database doesn't exist so catch it and then try a create if the user required that.
try
{
opened = true; // assume success
m_pDB->Open(CString("EventsLog.mdb"), false, false);
}
catch(CDaoException* e)
{
opened = false; // wrong assumption, didn't open
e->Delete();
}
if ((!opened) && (createIfRequired))
{
try
{
opened = true; // assume success
m_pDB->Create(CString("EventsLog.mdb"));
CreateActivityRecordStructure();
CreateActivityRecord("0.1.2.3", "Test sensor 1", "Temp OK", 0);
}
catch(CDaoException* e)
{
opened = false; // wrong assumption, didn't open
LPTSTR errors = new TCHAR[100];
e->GetErrorMessage(errors,100,NULL);
// ALWAYS ENDS HERE COMPLAINING IT CAN'T START DAO
AfxMessageBox(errors);
e->Delete();
}
}
_ConnectionPtr pConnection;
hr = pConnection.CreateInstance(__uuidof(Connection));
if (FAILED(hr))
{
return false;
}
_RecordsetPtr recordset;
hr = recordset.CreateInstance(__uuidof(Recordset));
if (FAILED(hr))
{
return false;
}
hr = pConnection->Open(strConnectionString, "", "", adOpenUnspecified);
// this ALWAYS fails regardless of any connection string I have tried - and I've tried a few.
Anything thats to do with 'wrappers around managed classes' just reveals piles of shite about /clr and what it is incompatible with.
I can't find a piece of example code anywhere on the internet that will compile and work.
Surely it is trivial - after all, what I am trying to do (at this stage) is not really any harder than opening a file!
|
|
|
|
|
What is your question?
The code you posted compiles? Runs? Doesn't behave as expected?
Why don't you use ADO ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
struct hostent *pHost;
int ip,i,j;
string str;
char ipc[6];
str="";
char ctrl[3] = {'\r','\n','\0'};
pHost = gethostbyname("google.com");
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{
for(j=0; j<pHost->h_length; j++)
{
ip = pHost->h_addr_list[i][j];
str += itoa(ip,ipc,10);
str += ".";
}
str+=ctrl;
}
alert(str);
I get an alert with four addresses one after the other. i get negative values. for example
-47.85.-103.103
-47.85.-103.104
-47.85.-103.109
-47.85.-103.99
when i tried ip-adress.com i got 74.125.43.104 for google
mine is a shared hosting and the values are less than 128 and i get only one address entry.
i have other alternates to find ip adress of an host and i want to try this too...
is it ok to get negative values... i haven't seen that...Today's Beautiful Moments are
Tomorrow's Beautiful Memories
modified on Monday, February 15, 2010 3:34 PM
|
|
|
|
|
You're seeing negative values because the hostent structure stores the bytes as signed chars. Take a look at inet_ntoa[^] for one way to turn it into a recognisable address.
|
|
|
|
|
You cannot get the IP address of any host on the internet in this way. The gethostbyname() function only performs a lookup in the local hosts database. IP address resolution for non-local hosts is accomplished via DNS servers.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Richard MacCutchan wrote: You cannot get the IP address of any host on the internet in this way.
Sure you can. Try this:
struct hostent *host = gethostbyname("www.google.com");
struct in_addr *ptr = (struct in_addr *) host->h_addr_list[0];
int nOct1 = ptr->S_un.S_un_b.s_b1;
int nOct2 = ptr->S_un.S_un_b.s_b2;
int nOct3 = ptr->S_un.S_un_b.s_b3;
int nOct4 = ptr->S_un.S_un_b.s_b4;
...
char *pIPAddr = inet_ntoa(*ptr); "One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
<br />
hostent* localHost;<br />
char* localIP;<br />
localHost = gethostbyname("vikku.info");<br />
localIP = inet_ntoa (*(struct in_addr *)*localHost->h_addr_list);<br />
alert(localIP);<br />
The above code worked well.
I want to find my ip address so that i can make an HTTP request.
I have been doing this by frequently checking online. since my space is a shared hosting the servers ip changes sometimes. So i want to find the ip of my server to make it automatic.
or i think it is best to use getaddrinfo
anyway will the above code holds good? or my first post?
Thanks to the three of you for your replies.
I am experimenting all.Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: I want to find my ip address...
Call gethostname() followed by gethostbyname() .
Jayapal Chandran wrote: since my space is a shared hosting the servers ip changes sometimes. So i want to find the ip of my server to make it automatic.
Isn't that the whole reason for using a host name rather than an IP address (to not be affected by IP changes)?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
For now this is all i need. May i know the other purposes?
But yet i want to see in practice the working of all these and the purposes behind.
I want to be aware of Networking from some base point. i have started from sockets... and i hope i have to branch more...Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: May i know the other purposes?
The other purposes of what?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
You have said the following...
~~~~
Isn't that the whole reason for using a host name rather than an IP address (to not be affected by IP changes)?
~~~~
I was not sure the scope of these functions but i thought you were saying there is more that this.
So, i hope you said the reason for using a host name than an ip address is to find the address.
am i confusing?
I should have said YES. but is there any other reason?Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
unsigned char ip,i,j;<br />
pHost = gethostbyname("google.com");<br />
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )<br />
{<br />
for(j=0; j<pHost->h_length; j++)<br />
{<br />
ip = (unsigned char)pHost->h_addr_list[i][j]; <br />
fprintf(f,"%d %u\r\n",ip,ip);<br />
str += itoa(ip,ipc,10);<br />
str += ".";<br />
}<br />
str+=ctrl;<br />
}<br />
alert(str);
so i changed unsigned to unsigned char(i did not check it properly)
and i could get googles ip addresses but still the one which i saw in
ip-adress.com did not appear. when i used gethostbyaddr i got bom01s01-in-f147.1e100.net which is
also googles for this ip 209.85.153.147 . why only four appears for gethostbyname?
if this is beyond the scope then we can drop this.Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: ...i could get googles ip addresses but still the one which i saw in
ip-adress.com did not appear.
Your IP address and Google's IP address are not going to match. Why would you think otherwise?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
was just curious. anyway. i need to learn more to understand these behind the scenes.
Meanwhile, i want to know what IDE has options like designing the user interface like in vb (visual studio 6.0). currently i am using DEV-C++ and the compiler is mingw for win32. I have to run the program to see how the width and height has been set for any control i create. I tried VS 6.0 but couldn't design a window. I am asking something like glade. Or do i have to migrate to VS 2003 or greater. I want to run my programs without the .NET framework. As i said i am a novice w.r.t .NET... a little of c# i have did. ?Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: Meanwhile, i want to know what IDE has options like designing the user interface like in vb (visual studio 6.0)....I tried VS 6.0 but couldn't design a window.
This makes no sense. Unless you did something just completely wrong, any version of VS will work.
Jayapal Chandran wrote: Or do i have to migrate to VS 2003 or greater.
If you don't require MFC, you might want to download VS2008 Express."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Oh. Thanks. I should consider that untill i tend to program the shell. I hope MFC is ideal for that.
meanwhile, i was looking at your other replies and came across turbo c.
I want to stop file creation in windows. I want to try the interrupts like i did in dos. KBD events, mouse, the screen interrupts. and the most needed int 21. besides these i enjoyed the terrific TSR. But how do i do that in window. I am trying to understand the shell concept so that i can write the registry to make my program appear in all context menus like winzip or notepad++. I am still lagging many topics. If you dont mind then please can you drop me some references. These are the things i was doing in Ms-Dos. At one point i cannot read write the far memory that is beyond 64kb. There were DPMI but i thought better to migrate to 32 bit c programs instead of being in 16 bit and trying beyond the scope topics. phew. sorry.Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: I want to try the interrupts like i did in dos. KBD events, mouse, the screen interrupts. and the most needed int 21.
Windows is going to keep most of that away from you.
Jayapal Chandran wrote: besides these i enjoyed the terrific TSR. But how do i do that in window.
The concept of a TSR in Windows does not exist, at least not how it was defined way back then. Windows has many processes that run "simultaneously." Creating another process is trivial.
Jayapal Chandran wrote: I am trying to understand the shell concept so that i can write the registry to make my program appear in all context menus like winzip or notepad++.
See here.
Jayapal Chandran wrote: At one point i cannot read write the far memory that is beyond 64kb.
No such thing in Windows. Far pointers went away with the 32-bit OS."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Yes, i read somewhere that TSR (the same way) cannot be done. but still. i want to moniter the processes which creates files and certain other processes. Thank you for the registry link. That is the first concept i did after coming here (32bit). I created tabs and radio buttons to restrict the users using certain options like right click on desktop, changing background, folder options. I want to program the explorer shell.
anyway. am i querying too much? beyond the scope of this thread? but despite that i get the answers and you are gladly helping me. How do you take it when there are lots of queries to your personally. It is going like consultation. Thank you a lot. and you can stop me anytime you want but if you really want to.
Next thing is i am writing a tray popup which will ping my server to see for any recent mails. IMAP.
I have experimented using PHP.(because a single function does a lot of work and easy to see the final result but i want a real window program to do that. so i all the networking stuff with php and then i implement in win32). The one draw back is negotiating with the TLS. IF i want to ping my server then that is fine. But if i want to ping google to see my mail status then i have to work with the certificates. This is the idea i assume that i should do if i have to deal with google. I hope c# could have options for doing this. But how about third party libraries for win32 to deal with TLS. Could you drop me some references? meanwhile i am still searching the internet and will continue searching till it is solved. Interesting all these network stuffs. ain't these? . ha.Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: I want to program the explorer shell.
Check out Michael Dunn's articles about that subject.
Jayapal Chandran wrote: anyway. am i querying too much? beyond the scope of this thread?
Yes, the thread subject is long gone. Feel free to start a new thread when you have other matters to discuss.
Jayapal Chandran wrote: How do you take it when there are lots of queries to your personally.
I answer few, if any, personal questions. If you mean directly/specifically to me, if I see the posts and have something useful to provide, I will. That way everyone benefits."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Yeah, specifically/directly/technical . Ok. I will maintain that. Thank you a lot. . Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
I was trying to get the ip of host name using getaddrinfo. The linked list updated by this function (addrinfo structure)has sockaddr type which has only to types. How to find ip from hostname using getaddrinfo?
MSDN has stated that it is better to use getaddrinfo instead of gethostbyname.Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Of course you can; I wonder where my brain was the other day? txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Yes. i am experimenting all. thank you. Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Your question prompted me to revisit the use of the various network functions, which I have had no occasion to use for about four years. I spent all evening working on some associated code and think I now understand them as well as I did then (obviously not completely), so thanks for telling me what can be done, and pushing me to relearn what I had almost forgotten. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Then how it is working?
Actually, i update my win32 program with the latest ip address of my shared hosting.
Instead of this i want to resolve the ip in my program.
The address what i dot from ip-adress.com is the same as the one which i got through the snippets provided here. Then what would be the variation in resolving a local address and resolving using DNS...
Only if our ISP updates the addresses we will get a copy of those... How to fetch from DNS...?
There are lots of questions in a whirl #@*& Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|