|
Ok I need some help here. I have been through the MSDN sites and tried multiple types of sockets and streams.
What I am trying to do is this. I have a C++/CLI forms app using /clrsafe runtime.
What I need is socket so I can send a string like "^0!NO\r" through a raw TCP port. There is only a "one way connection here" the response will have to be on a listener stream but the system will not be making a socket connection with the program. I have completed this in Python script so those who know python this is how I did it.
Chost = '169.254.232.50'
Cport = 1555
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket Created'
cam = socket.socket()
try:
s.bind((host, port))
except socket.error , msg:
print 'Bind failed. Error Code : ' +str(msg[0]) + ' Message ' + msg[1]
sys.exit()
Any help would be great,
|
|
|
|
|
The code is much the same as you have above, although you would use connect rather than bind ; see this tutorial[^].
Veni, vidi, abiit domum
|
|
|
|
|
Hi, I actually have 2 problems. If i enter gcgc, it should give me 4 when counting G's and C's but it gives me 3 instead. Also, the program doesn't stop by itself (I have to press control C to get out). What is wrong with my code?
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
char input = ' ';
int count = 0;
char newinput = ' ';
int newcount = 0;
cout << "Enter the DNA strand:";
cin >> input;
while (input != '\n')
{cin.get(input);
switch (toupper(input))
{
case 'C':
count++;
break;
case 'G':
count++;
break;}}
cout << "There are " << count << " C's and G's in this DNA strand."<< endl;
while (input != '\n')
{cin.get(input);
switch (toupper(input))
{
case 'B':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin>>newinput;
cin.clear();
cin.ignore('\n');
break;
case 'D':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'E':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'F':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'H':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'I':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'J':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'K':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'L':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'M':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'N':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'O':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'P':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'Q':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'R':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'S':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'U':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'V':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'W':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'X':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'Y':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
case 'Z':
cout << "Invalid sequence! Please enter the correct nucleotide sequence:";
cin.clear();
cin.ignore('\n');
break;
}
}
while (newinput != '\n')
{ cin.get(newinput);
switch (toupper(newinput))
{ case 'C':
newcount++;
break;
case 'G':
newcount++;
break;
}
}
cout << "There are " << newcount << " C's and G's in this DNA strand." << endl;
return 0;
}
|
|
|
|
|
You could simplify this by removing all those redundant case blocks and replaing them with a single default: . You could then use your debugger to find out why it does not break out of the loop.
Use the best guess
|
|
|
|
|
I have a native dll with some code that I want to leverage from managed C# applications.
So I wrote a C++/CLI class library to implement an wrapper assembly.
This works well but it creates a maintenance issue.
In the C# client project, I added a reference to my wrapper assembly and whenever I build the client project, the assembly dll gets copied to the build target folder.
However the dependent native dll does not get copied.
So my question is, how do I include the native dll in the wrapper assembly dependency so that they are both copied when the client project is built.
|
|
|
|
|
AFAIK, you don't. What you could do is have a post-build step which copies the files over.
|
|
|
|
|
I'll second this. We have a post-build step copy the DLLs too.
John
|
|
|
|
|
Am getting 'An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in CallingExe.exe
Additional information: External component has thrown an exception.' error when i try to call a dll generated with C# in my MFC code.
Have successfully generated the .tlb file using RegAsm.exe and also installed it using gacutil. both these were successfull. Have attached my code for reference.
MFC Code:
#using <mscorlib.dll>
#import "C:\\Programing\\Projects\\Visual Basic\\native calls\\vchash\\ManagedDLL\\ManagedDLL\\bin\\Debug\\ManagedDLL.tlb" raw_interfaces_only
using namespace ManagedDLL;
void CCallingExeDlg::OnBnClickedOk()
{
HRESULT hr = CoInitialize(NULL);
ICalculatorPtr pICalc(__uuidof(ManagedClass));
}
C# Code:
using System;
using System.Runtime.InteropServices;
namespace ManagedDLL
{
[ComVisible(true)]
[Guid("1A9ECDD2-24FC-4f9b-97BF-BF170B16CB38")]
public interface ICalculator
{
int Add(int Number1, int Number2);
};
[ComVisible(true)]
[Guid("9CEFF09D-7140-451e-A85E-2341A7C978FA")]
public class ManagedClass : ICalculator
{
public int Add(int Number1, int Number2)
{
return Number1 + Number2;
}
}
}
Am getting error in 'ICalculatorPtr pICalc(__uuidof(ManagedClass));' line of MFC code
Am stuck with this from past two weeks.
Any help would be greatly appreciated.
Dhamu
|
|
|
|
|
You cannot directly use a managed dll from unmanaged code as far as I know. You need to take some other actions as detailed in some of these articles[^].
Use the best guess
|
|
|
|
|
I have a high configurable pc with MS-Office 2010 package, i have implemented one application(in c++/cli) which will write plenty of data in no'of excel sheet(single workbook)so after writing in 8 sheets suddenly it pop-ups one error message saying"Excel cannot complete this task with available resources Choose less data or close other applications". Task Manager tells me I have plenty of resources left. Does anyone have any ideas as to what might be happening and how to fix it?
Note: I can't reproduce it again since application will do lot of process(almost 4days) to generate 8 sheets
|
|
|
|
|
Given that it is 4 days to generate the 8 sheets, it is my guess that you have a memory leak or a resource/handle leak. I know you say that Task Manager says you have plenty of resources left, but this really sounds like a leak of some kind.
I would start by double checking the freeing of every resource you allocate. Make sure they are freed in a timely manner also.
|
|
|
|
|
Hi David, now i realized that i am not saving the excel file till completion of the report generation so what i am suspecting, each excel sheet will have maximum rows 1048576 that means
1048576 * 8 = 8388608 rows of data(this data is a huge) it holding on RAM. Now what i will do i will save the excel file for each 5 sheets completion and continue to generate report.
In this application i am also using number of Dictionary objects, so i will also take care to freed these objects as per you suggestion.
Thanks for you support
|
|
|
|
|
I have a set of project folders which are compilable using make files and as of now i am compiling using nmake at command prompt.. i want the entire folder structure to be in a project or a solution file has to be built so that i can compile like a regular Project and must be able to place breakpoint in VS6.0 pls help
PS: Code is in plain C and C++ and NO MFC Used ...
|
|
|
|
|
Shyam Kodase wrote: Code is in plain C and C++
Then you would be better off asking in the appropriate forum[^] since this forum is for mangaged C++.
|
|
|
|
|
Shyam Kodase wrote: Code is in plain C and C++ So why have you posted this in the Managed C++/CLI forum?
However, as to your question: The best way to do this would be to leave the existing folders intact until the new projects are all building successfully.
- Using Visual Studio, create a new empty project for the first existing project in your set. This will create a solution folder and a project folder underneath it.
- Copy the source files (via Windows Explorer) from the existing project into the new project folder.
- Using Visual Studio, add the files into the project (header, resource, source etc).
- Build the project and correct any errors.
- Add a new blank project to the solution and repeat the above process.
- Repeat for all remaining projects.
Use the best guess
|
|
|
|
|
I have managed c++ ref type class in DLL. In C# application, I am using the this managed DLL and referring the managed class as below:
CManaged * obj = new CManaged();
with help of pointer to instance, I am accessing the member methods of CManaged class.
Everything is working fine on VS 2010.
Question:
How C# (managed code) handle the pointers?
Is it depend on my Visual Studio version?
|
|
|
|
|
NAVALMAN wrote: Is it depend on my Visual Studio version? No, Visual Studio is an IDE and has nothing to do with the code generation or running of programs.
Use the best guess
|
|
|
|
|
Thanks Richard MacCutchan.
How the pointers are handled in Manged C++?
|
|
|
|
|
What do you mean?Pointers are pointers, nothing more. If you are asking about handing off unmanaged objects to managed code, then you need to look at some of these links[^].
Use the best guess
|
|
|
|
|
NAVALMAN wrote: How C# (managed code) handle the pointers?
Since it is managed C++ it probably doesn't do anything especially clever. If C# is doing anything at all, it is just wrapping it in a small object.
The C# specification might spell it out in detail.
|
|
|
|
|
Thank you
|
|
|
|
|
I have a legacy C++ native code application that implements a class hierachy with some inheritance.
I have to re-implement the application within a managed framework.
TI would like to reuse the unmanged class hierarchy from the managed application and still benefit from the polymorphism built in to my unmanaged class hierarchy.
Do I have to write a C++/CLI wrapper for each unmanaged class in the hierarchy and duplicate the inheritance structure within the wrappers?
|
|
|
|
|
You might do it that way, but it might actually be better to put the native parts into managed DLLs using the wrappers and then using the DLLs from your managed application.
It all depends on what you are trying to do. I wouldn't get too wrapped up in trying to preserve the old hierarchy in the managed world though.
|
|
|
|
|
Assuming that you really do need to expose the full class hierarchy as managed types to managed code then yes, I think you're left duplicating the hierarchy with wrapper ref classes.
If the client managed application is also guaranteed to be C++/CLI (and not C#) it could #include the native class hierarchy intact and use it directly. If you want to allow C# then I'd use wrapper classes with the PIMPL idiom.
Also, hopefully your native classes don't use multiple inheritance since a managed class can only have one non-interface base class.
John
|
|
|
|
|