|
Hello I'm tryin to use the library to debug from different threads but I've strange behaviour i.e. two outuput on the same line.
|
|
|
|
|
Hi _marsim_!
sorry, but the console functions are not thread safe at all!
If you need thread safe functions, you have to make some changes in the ConsoleLibrary.h modul.
You can use a CMutex-Objekt to make it thread safe.
Ciao,
Manfred
|
|
|
|
|
|
Hi Martin,
yes you're right. In VS2005 there are many enhancements in the Conole class.
You do not longer need my library!
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo cki;
ConsoleKey key = 0;
bool bKeyIsAvailable;
Console.Clear();
Console.ForegroundColor = ConsoleColor.Cyan;
do
{
bKeyIsAvailable = Console.KeyAvailable;
if (bKeyIsAvailable)
{
cki = Console.ReadKey(true);
key = cki.Key;
if (key == ConsoleKey.F1)
{
Console.WriteLine("You've pressed F1.");
}
}
} while (key != ConsoleKey.Escape);
Console.WriteLine("Ready...");
}
}
}
|
|
|
|
|
Oh, I would not say your library was obsolete.
In fact, where we programmers are forced to still use .Net 1.1, it is very handy!
Especially in large enterprises there are many "legacy" servers (ie: .Net 1.1) where installing a newer .Net version is "forbidden" due to issues it would cause.
Sounds hard to believe, what with all the steps Microsoft has taken to provide framework interoperability (sic), but "It's the real gritty life out here, baby!"
Cheers and thanks,
Martin
--
MCAD (.Net)
martinstoller.com
--
|
|
|
|
|
Hi,
The ConsoleLibrary project doesn't seem to want to compile in Visual Studio 2005. It gets a linker error fatal error LNK1181: cannot open input file 'LIBC.lib'.
I looked on Google and tried various workarounds suggested (such as removing LIBC.lib reference from Linker Input; adding LIBC.lib to "ignore specific library"; but that didn't help.
Do you have any suggestions on making this work?
Eric Taneda
onsitehelp.com
|
|
|
|
|
Hi Eric,
in VS2005 there are many enhancements in the Conole class.;)
You do not longer need my library!
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo cki;
ConsoleKey key = 0;
bool bKeyIsAvailable;
Console.Clear();
Console.ForegroundColor = ConsoleColor.Cyan;
do
{
bKeyIsAvailable = Console.KeyAvailable;
if (bKeyIsAvailable)
{
cki = Console.ReadKey(true);
key = cki.Key;
if (key == ConsoleKey.F1)
{
Console.WriteLine("You've pressed F1.");
}
}
} while (key != ConsoleKey.Escape);
Console.WriteLine("Ready...");
}
}
}
|
|
|
|
|
|
i'm happy to help you
Manfred
|
|
|
|
|
Hey, just wondering, but could you make this into a C++ thing too, cause I really need it in C++
thanks
http://destinationoakdale.tripod.com/
|
|
|
|
|
Hello,
I've a problem, I've created a windows form, into this project i must use a C code (that run perfectly in visula studio) that create some trees using a matrix that is generated by the c# code, how can I make it? I must create a DLL with C code and pass it the matrix?
Thanks.
Ciao, Andrea.
|
|
|
|
|
Hello Andrea,
it's the best way to build a Class Library (like my ConsoleLibrary ) as a new project in your projectgroup.
You have to add to your C# Project a new project (File->Add Project->New Project...)
Choose Visual C++-Projects -> Class Library (.NET) and give a name (e.g. MyCLibrary)
Open project-properties of MyClibrary. Add Linker-Input LIBC.LIB for all configurations (Debug and Release).
(The default entry was "nochkclr.obj mscoree.lib")
Open then Stdafx.h file and add the line:
#include "windows.h"
Open the MyCLibrary.h file and add your c-Functions.
Make them public. Here is a example:
<br />
<br />
<br />
#pragma once<br />
<br />
using namespace System;<br />
<br />
#include <conio.h><br />
<br />
<br />
namespace MyCLibrary<br />
{<br />
public __gc class Class1<br />
{<br />
public:<br />
static int SumTest(int a, int b)<br />
{<br />
int sum = a + b;<br />
return sum;<br />
}<br />
<br />
static void Sleep(int dwMiliseconds)<br />
{<br />
::Sleep(dwMiliseconds);<br />
}<br />
};<br />
}<br />
Create the library.
Change to your C# project.
Add reference, choose projects and then MyClibrary
Open your cs file
Add the line:
using MyCLibrary;
Now you can use your c-functions:
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
int sum = Class1.SumTest(1,2);<br />
}<br />
Have fun.
|
|
|
|
|
Hello ManiB
Fisrt of all I want to say Thanks to you to help me, I have applied your instructions, but if I put in MyCLibrary a simple C code like you function the pogram run with no problem, but if I put my C code that usually with no problems in visual studio when I try to run it Visual studio say me that there errors, it make a problem whit all function that I declared in my C code and it say that "Local function definitions are illegal". Do you have an idea about this problem?
Thanks, Andrea.
|
|
|
|
|
remember the #includes!
can you post your c-code and the error you got?
|
|
|
|
|
This is the code:
-------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*CREO LA STRUTTURA DATI ALLA BASE DELL'ALBERO*/
struct elemento
{
unsigned int x, y;
char tipo;
float peso;
struct elemento *dad, *son_s, *son_c, *son_d;
};
/*USO UN TYPEDEF PER COMODITA'*/
struct elemento *root;
struct elemento *now;
struct elemento *dad;
int Mat[5][5]={{0,0,0,0,0},{0,0,0,0,0},{1,1,1,1,1},{0,0,0,0,0},{0,0,0,0,0}};
/*FUNZIONI DA REALIZZARE*/
struct elemento *create_root(int i, int j); /*creazione root*/
void print_node(struct elemento *now); /*visualizza il contenuto di un nodo*/
struct elemento *aggiungi_figlio_s(int i, int j,struct elemento *now);
struct elemento *aggiungi_figlio_c(int i, int j,struct elemento *now);
struct elemento *aggiungi_figlio_d(int i, int j,struct elemento *now);
void trova_figlio(int i, int j,struct elemento *now); /*trova i figli data la radice*/
void percorri_albero(struct elemento *now, int Im, int v, int mat_v[3][5], float arr_v[5]);
void stampa_prodotto(float arr_v[5], float P,int i);
/*creazione root*/
struct elemento *create_root(int i, int j)
{
struct elemento *temp;
if((temp=(struct elemento *)malloc(sizeof(struct elemento)))==NULL)
{
printf("\nErrore creazione della radice");
return NULL;
}
temp->tipo='r';
temp->x=i;
temp->y=j;
temp->peso=1;
temp->dad=NULL;
temp->son_s=NULL;
temp->son_c=NULL;
temp->son_d=NULL;
return temp;
}
/*visualizza il contenuto di un nodo*/
void print_node(struct elemento*now)
{
printf("\n***\n\tTipo: %c\n\tX: %d\n\tY: %d\n\tPeso: %f\n***",now->tipo,now->x,now->y,now->peso);
printf("\n+++\n\tDad (puntatore): %p\n\tson sinsitro (puntatore): %p\n\tson centrale (puntatore): %p\n\tson destro (puntatore): %p\n+++",now->dad,now->son_s,now->son_c,now->son_d);
}
struct elemento *aggiungi_figlio_s(int i, int j,struct elemento *now)
{
struct elemento *tmp;
if((tmp=(struct elemento *)malloc(sizeof(struct elemento)))==NULL)
{
printf("\nErrore creazione figlio da aggiungere");
return 0;
}
tmp->tipo='n';
tmp->x=i;
tmp->y=j;
tmp->peso=0.25;
tmp->dad=now;
tmp->son_s=NULL;
if(now->son_s==NULL)
{
now->son_s=tmp;
}
return tmp;
}
struct elemento *aggiungi_figlio_c(int i, int j,struct elemento *now)
{
struct elemento *tmp;
if((tmp=(struct elemento *)malloc(sizeof(struct elemento)))==NULL)
{
printf("\nErrore creazione figlio da aggiungere");
return 0;
}
tmp->tipo='n';
tmp->x=i;
tmp->y=j;
tmp->peso=0.5;
tmp->dad=now;
tmp->son_c=NULL;
if(now->son_c==NULL)
{
now->son_c=tmp;
}
return tmp;
}
struct elemento *aggiungi_figlio_d(int i, int j,struct elemento *now)
{
struct elemento *tmp;
if((tmp=(struct elemento *)malloc(sizeof(struct elemento)))==NULL)
{
printf("\nErrore creazione figlio da aggiungere");
return 0;
}
tmp->tipo='n';
tmp->x=i;
tmp->y=j;
tmp->peso=0.25;
tmp->dad=now;
tmp->son_d=NULL;
if(now->son_d==NULL)
{
now->son_d=tmp;
}
return tmp;
}
void trova_figlio(int i, int j,struct elemento *now)
{
int mat_v[3][5];
float arr_v[5];
if (Mat[i-1][j+1]==1) // Figlio sinistro
{
struct elemento *tmp1;
if((tmp1=(struct elemento *)malloc(sizeof(struct elemento)))==NULL)
{
printf("\nErrore creazione figlio da aggiungere");
}
printf("\nAggiunto sinistro");
tmp1=aggiungi_figlio_s(i-1,j+1,now);
printf("\nAggiunto");
printf("\n\tX: %d\n\tY: %d\n\tPeso: %f\n***",tmp1->x,tmp1->y,tmp1->peso);
print_node(tmp1);
printf("\nFiglio di");
printf("\n\tX: %d\n\tY: %d\n***",tmp1->dad->x,tmp1->dad->y);
getchar();
if((j<4)&&((i>-1)&&(i<4)))
{
trova_figlio(i-1,j+1,tmp1);
}
if(tmp1->y==4)
{
percorri_albero(tmp1,0,4,mat_v,arr_v);
}
}
if (Mat[i][j+1]==1) // Figlio centrale
{
struct elemento *tmp2;
if((tmp2=(struct elemento *)malloc(sizeof(struct elemento)))==NULL)
{
printf("\nErrore creazione figlio da aggiungere");
}
printf("\nAggiunto centrale");
tmp2=aggiungi_figlio_c(i,j+1,now);
printf("\nAggiunto");
printf("\n\tX: %d\n\tY: %d\n\tPeso: %f\n***",tmp2->x,tmp2->y,tmp2->peso);
print_node(tmp2);
printf("\nFiglio di");
printf("\n\tX: %d\n\tY: %d\n***",tmp2->dad->x,tmp2->dad->y);
getchar();
if (j<3)
{
trova_figlio(i,j+1,tmp2);
}
if(tmp2->y==4)
{
percorri_albero(tmp2,0,4,mat_v,arr_v);
}
}
if (Mat[i+1][j+1]==1) // Figlio destro
{
struct elemento *tmp3;
if((tmp3=(struct elemento *)malloc(sizeof(struct elemento)))==NULL)
{
printf("\nErrore creazione figlio da aggiungere");
}
printf("\nAggiunto destro");
tmp3=aggiungi_figlio_d(i+1,j+1,now);
printf("\nAggiunto");
printf("\n\tX: %d\n\tY: %d\n\tPeso: %f\n***",tmp3->x,tmp3->y,tmp3->peso);
print_node(tmp3);
printf("\nFiglio di");
printf("\n\tX: %d\n\tY: %d\n***",tmp3->dad->x,tmp3->dad->y);
getchar();
if((j<3)&&(i<4))
{
trova_figlio(i+1,j+1,tmp3);
}
if(tmp3->y==4)
{
percorri_albero(tmp3,0,4,mat_v,arr_v);
}
}
}
void percorri_albero(struct elemento *now, int Im, int v, int mat_v[3][5], float arr_v[5])
{
FILE *stream = fopen("alberi.txt","a");
int i=0;
int a=0;
int b=0;
int z=4;
float P;
i=Im;
z=v;
mat_v[1][i]=now->x;
fprintf(stream,"\nX:%d",mat_v[1][i]);
printf("\n\tX :%d",mat_v[1][i]);
mat_v[0][i]=now->y;
fprintf(stream,"\nY:%d",mat_v[0][i]);
printf("\n\tY :%d",mat_v[0][i]);
arr_v[i]=now->peso;
printf(stream,"\nPeso:%f",arr_v[z]);*/
i=i+1;
if (now->dad!=NULL)
{
printf("\nI:%d",i);
printf("\nZ:%d",z);
now=now->dad;
z--;
percorri_albero(now,i,z,mat_v,arr_v);
}
else
{
FILE *stream = fopen("alberi2.txt","a");
for(i=4;i>-1;i--)
{
fprintf(stream,"%d",mat_v[0][i]);
}
fprintf(stream,"\n");
for(i=4;i>-1;i--)
{
fprintf(stream,"%d",mat_v[1][i]);
}
fflush(stream);
fclose(stream);
P=arr_v[0];
stampa_prodotto(arr_v,P,1);
}
}
void stampa_prodotto(float arr_v[5], float P,int i)
{
FILE *stream = fopen("alberi2.txt","a");
if (i==5)
{
fprintf(stream,"\n");
fprintf(stream,"%f",P);
fflush(stream);
fclose(stream);
}
P=P*arr_v[i];
if((i==1)||(i==2)||(i==3)||(i==4))
{
i++;
stampa_prodotto(arr_v,P,i);
}
}
int main(char *argv, int argc)
{
int j=0;
int i=0;
for (i=0; i<5; i++)
{
printf("\nIndice i :%d --- Indice j :%d",i,j);
printf("\nMatrice :%d",Mat[i][0]);
getchar();
if(Mat[i][0]==1)
{
now=create_root(i,j);
printf("\nIndice i :%d --- Indice j :%d",i,j);
printf("\nCreata radice");
print_node(now);
getchar();
trova_figlio(i,j,now);
}
}
return 0;
}
-----------------------------------------------------
ERROR:
'main' : local function definitions are illegal
'stampa_prodotto' : local function definitions are illegal
'percorri_albero' : local function definitions are illegal
'trova_figlio' : local function definitions are illegal
'aggiungi_figlio_d' : local function definitions are illegal
'aggiungi_figlio_c' : local function definitions are illegal
'aggiungi_figlio_s' : local function definitions are illegal
'print_node' : local function definitions are illegal
'create_root' : local function definitions are illegal
|
|
|
|
|
Hi AndRy82,
i think you got the error because you insert your code at the wrong place.
This is the MyCLibrary.h i wrote for you.
You can compile it, but unfortunately you can't run it. The main problem is, you can't use every c-function in your c-code. The printf() is one of them, because where should go the output?
So I think you have to rewrite your c-code to c# code. It's not very complicated.
Good look,
Manfred
|
|
|
|
|
Hello ManiB
Firts, thanks for your help, I Make a mistake, I put printf in C code only to see if the program was working on correct data, in reality I need only to write into a file with fprintf. I have deleted all printf and I have make modify in the final part of the code:
public __gc class MyCLib
{
public:
//static int __gc Mat[5][5]={{0,0,0,0,0},{0,0,0,0,0},{1,1,1,1,1},{0,0,0,0,0},{0,0,0,0,0}}; //FAIL!
//static int Mat __gc [,] = new int __gc [5,5]; // ok
static public void test_main()
{
int i=0;
int j=0;
int Mat[5][5]={{0,0,0,0,0},{0,0,0,0,0},{1,1,1,1,1},{0,0,0,0,0},{0,0,0,0,0}};
for (i=0; i < 5; i++)
{
if(Mat[i][0]==1)
{
now=create_root(i,j);
trova_figlio(i,j,now,Mat);
}
}
}
};
}
if i run this there are't error and the application start, but it stop at this istructions -> now=create_root(i,j); says this problem: Additional information: Object reference not set to an instance of an object. I can't undersand.
I can bypass all of this problem only if in C language I can open a bitmap image and I can get the color of every pixel to make a matrix whit 1 if is black and 0 if is wihte, do you think that is possible?
thanks, Andrea.
|
|
|
|
|
|
First - this is truly EXCELLENT work. Second, there seems to be no way to read the current fore/background colors. Im wanting to implement an ANSI interpreted display (ESC[7m = reverse video, etc). Cursor movement and color works great, but in order to do reverse video, I need to be able to read the current colors.
Thanks again for this awesome work.
|
|
|
|
|
Hello xlar54,
thanks for using my library.
To get the current attribute of a charcter you need the function ReadConsoleOutputAttribute() and to get the current character itselve you need the function ReadConsoleOutputCharacter().
Both are not implemented in my library. Can you add them yourselve, or should i do the work?
Ciao, Manfred
|
|
|
|
|
project (in 'ConsoleLibrary.cpp' file) and it running without falling.
That what make me to believe that it had something with project's properties.
Can you write what should i add (or change) in project properties to be able to allocate memory?
Yossi
Ayallon valley - Israel
|
|
|
|
|
Hi,
you are right. The first times in my ConsoleLibrary the malloc function didn't catch an exception.
But then i included <math.h> and after than the exception appear!
It's very strange and I couldn't found the reason.
Sorry
Manfred
|
|
|
|
|
I'll try to find a way of doing it. If I'll find, I'll send you whatever I'll figured out.
If you'll find a way for doing it, I'll be very happy if you'll send me explanation about what ever you fount.
Have a nice day
Yossi
Ayallon valley - Israel
|
|
|
|
|
Hi Manfred
I try to find a way of using allocation (malloc) in c files that used in c# project. right now i have no idea how I'm going to do it. I would like to hear your opinion about a problem with allocation.
do you think it just a problem with properties definitions or maybe it a problem caused because of using c# compiler and there is no chance to do it ?
have a nice day
Yossi
Ayallon valley - Israel
|
|
|
|
|
Hi,
i think there must be an solution! Try to find a hint in other usegroups or google for it.
Sorry that i can't help you any more
Ciao,
Manfred
|
|
|
|
|