SAFEARRAY를 사용한 VARIANT ARRAY(배열) 다루기(VC++)

VB의 경우 VARIANT관련해서 조작은 아주 간편하다. VB만 사용하는 개발자라면 VARIANT  Type의 자료형이 존재한다는 사실조차 의식하지 못할 정도이다.

MFC (VC++)에서 VARIANT 와 VARIANT ARRAY(배열)를 사용하는 방법은 다소 까다롭다.
물론 내가 처음 VC++을 접할 때 OLE,COM등에 대해 별로 관심이 깊지 않았던 탓에 VARIANT를 다룰 기회가 없었던 이유도 있지만, 사용의 필요성을 느끼지 못했던 것도 사실이다.

그런데 어느 순간부터 사용하는 개발툴이 하나 둘 늘어나기 시작했다.
현업에서 일을 하다 보면 내가 사용하지 않았던 개발언어를 다루어야 할 경우가 생긴다. 다른 소스를 참조해야 하거나 여러 부서 또는 다른 회사와 공동작업을 해야 하는 경우도 있다.
이럴 때 dll,ATL,COM 을 사용하면 개발언어간의 장벽 사이에서 유연하게 재사용 가능한 코드를 작성할 수 있다.  그런데 라이브러리에 서 작성한 함수에 인자로 전달하는 변수형의 호환성이 항상 문제가 된다. VARIANT는 다른 종류의 개발 언어 사이에서 서로호환 되는 변수형이다. 

또한 VARIANT ARRAY(배열)을 다루는 함수는 SAFEARRAY임을 잘 기억하자.

아래의 예는 복합적인 변수형식을 VARINT Type 포인터로 넘겨서 처리 하는 방법 이다.

//thread에서 처리 가능하도록 Void Type의 자료넘김
DWORD  Function(LPVOID lpParam)
{
LPMITEM p_item=(LPMITEM)lpParam;//파라메터로 넘기기 위해 정의된 구조체
p_item->b_Thread_Run=TRUE;
//내가만든 ATL Class를 인자로 넘겨 받는다
CComObject<CMyclass>* p_Simul
=(CComObject<CMyclass>*)p_item->p_sim;
p_Simul->Test((int*)&b_OK);  //ATL Class에 정의된 함수 호출
////////////////////////////////////////
// 함수의 실행 결과를 다중배열 복합 Data로 받기 위한 Variant Point
VariantInit(&p_item->v_Rtn);   // Variant 초기화
V_VT(&p_item->v_Rtn) = (VT_VARIANT|VT_ARRAY);//Variant Type의 배열선언
//2개의 Variant 배열생성
V_ARRAY(&p_item->v_Rtn) = SafeArrayCreateVector(VT_VARIANT, 0, 2);
////////////////////////////////////////
VARIANT *p_var=NULL,*pv_child=NULL;
VARIANT t_var;
//Variant의 Array를 가져오기 및 Lock 해제
SafeArrayAccessData(p_item->v_Rtn.parray, reinterpret_cast<void**>(&p_var));
///첫 번째 배열에 2개의 Variant 배열을 할당하여 만들기
V_VT(&p_var[0]) = (VT_VARIANT|VT_ARRAY);
V_ARRAY(&p_var[0]) = SafeArrayCreateVector(VT_VARIANT, 0, 2);
//할당된 배열에서 Variant Point가져오기
SafeArrayAccessData(p_var[0].parray, reinterpret_cast<void**>(&pv_child));
//문자열 형태의 변수 넣기
t_var=_variant_t("NAME");
VariantCopy(&pv_child[0],&t_var);
//넘겨진 클래스의 멤버변수의 값을 가져오기
t_var=_variant_t(p_Simul->id_Name);
VariantCopy(&pv_child[1],&t_var);
//첫 번째 배열에
Variant 배열을 넣고 Lock실행 SafeArrayUnaccessData(p_var[0].parray);
/////////////////////////////////////////// /// 첫 번째 배열과 같은 방법으로 두 번째 배열도 값을 할당
V_VT(&p_var[1]) = (VT_VARIANT|VT_ARRAY);
V_ARRAY(&p_var[1]) = SafeArrayCreateVector(VT_VARIANT, 0, 2);
SafeArrayAccessData(p_var[1].parray, reinterpret_cast<void**>(&pv_child));
t_var=_variant_t("RESULT");
VariantCopy(&pv_child[0],&t_var);
t_var=_variant_t(b_OK);
VariantCopy(&pv_child[1],&t_var);
SafeArrayUnaccessData(p_var[1].parray);
/////////////////////////////////////////// //최상위 배열
Lock SafeArrayUnaccessData(p_item->v_Rtn.parray);
VariantClear(&t_var);
VariantClear(p_var);
VariantClear(pv_child);
p_item->b_Thread_Run=FALSE;
p_item=NULL;
p_Simul=NULL;
return 0;
}

여기서 주목 해야 할 부분은 SafeArrayAccessData에서 Variant Point로 접근하는 부분과 SafeArrayUnaccessData를 사용해서 Lock을 시키는 부분이다.
 

“SAFEARRAY를 사용한 VARIANT ARRAY(배열) 다루기(VC++)”의 131개의 댓글

  1. Howdy! I know this is somewhat off-topic however I had to ask.
    Does managing a well-established blog like yours take a massive amount
    work? I’m brand new to operating a blog however I do write
    in my journal every day. I’d like to start a blog so I will be able to share my
    own experience and views online. Please let me know if you have any recommendations or tips for new aspiring bloggers.

    Appreciate it!

  2. I loved as much as you’ll receive carried out right here.

    The sketch is attractive, your authored material stylish.

    nonetheless, you command get got an nervousness over
    that you wish be delivering the following.
    unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case
    you shield this increase.

  3. I just want to mention I am just all new to blogging and site-building and truly liked you’re web blog. Most likely I’m likely to bookmark your website . You surely have fantastic articles and reviews. With thanks for sharing your webpage.

  4. I discovered your blog site on google and also check a few of your very early blog posts. Remain to keep up the very good run. I just added up your RSS feed to my MSN News Reader. Seeking forward to finding out more from you in the future!?

  5. Excellent blog! Do you have any tips and hints for aspiring writers? I’m hoping to start my own blog soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely confused .. Any tips? Bless you!

  6. Hi, very exciting posting. My sister and I have recently been looking for comprehensive details about this type of stuff for some time, however we could hardly until now. Do you consider you can create several youtube videos about this, I believe your webblog would be far more thorough in case you did. In any other case, oh well. I am going to be checking on this web site within the forseeable future. Email me to maintain me up to date. granite countertops cleveland

  7. Youre so great! I do not suppose Ive check out anything similar to this before. So good to find somebody with some initial thoughts on this subject. realy thanks for starting this up. this website is something that is required on the internet, someone with a little creativity. useful job for bringing something brand-new to the net!

  8. After study a few of the blog posts on your web site now, and also I genuinely like your method of blog writing. I bookmarked it to my bookmark site list as well as will be inspecting back soon. Pls have a look at my web site too as well as let me understand what you believe.

  9. After I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I recieve four emails
    with the exact same comment. There has to be a way you can remove me from that service?

    Appreciate it!

  10. There are definitely a great deal of details like that to take into account. That is an excellent indicate raise. I provide the thoughts above as general ideas however clearly there are inquiries like the one you raise where one of the most vital thing will certainly be operating in straightforward good faith. I don?t understand if best methods have arised around things like that, however I am sure that your work is clearly recognized as a level playing field. Both boys and ladies really feel the effect of simply a moment?s satisfaction, for the remainder of their lives.

  11. After study a few of the post on your web site now, and also I genuinely like your means of blogging. I bookmarked it to my bookmark web site list and also will certainly be checking back quickly. Pls take a look at my web site too and let me understand what you assume.

  12. Youre so great! I do not intend Ive read anything like this prior to. So nice to find someone with some original ideas on this subject. realy thanks for beginning this up. this web site is something that is required on the web, someone with a little originality. useful job for bringing something brand-new to the web!

  13. Can I simply claim what a relief to locate somebody that in fact knows what theyre talking about on the web. You definitely know exactly how to bring a problem to light and also make it vital. Even more people require to read this as well as understand this side of the story. I cant think youre not extra popular because you definitely have the gift.

  14. Good post. I learn something a lot more tough on various blogs day-to-day. It will certainly always be stimulating to review content from various other authors and also practice a little something from their store. I?d like to make use of some with the material on my blog site whether you don?t mind. Natually I?ll give you a web link on your internet blog site. Many thanks for sharing.

  15. Youre so awesome! I do not intend Ive check out anything like this before. So great to locate somebody with some original ideas on this subject. realy thanks for beginning this up. this web site is something that is needed online, a person with a little originality. helpful work for bringing something brand-new to the internet!

  16. Aw, this was a really wonderful blog post. In idea I would like to place in creating like this additionally? taking some time and actual effort to make a great article? however what can I claim? I procrastinate alot and also never appear to get something done.

  17. 핑백: how to rank my site in alexa

  18. Can I simply state what an alleviation to find somebody who actually recognizes what theyre speaking about on the web. You certainly recognize exactly how to bring a problem to light and make it important. Even more people require to read this as well as recognize this side of the story. I angle think youre not more prominent due to the fact that you definitely have the gift.

  19. I truly wanted to write a brief word in order to say thanks to you for some of the marvelous advice you are giving out at this website. My prolonged internet lookup has finally been paid with sensible know-how to write about with my neighbours. I would mention that we visitors actually are unequivocally lucky to dwell in a fabulous site with so many outstanding people with insightful techniques. I feel rather grateful to have encountered your web pages and look forward to tons of more awesome moments reading here. Thank you once more for everything.

  20. Thank you a lot for providing individuals with an extraordinarily wonderful chance to read in detail from this website. It is always very pleasing and as well , stuffed with a great time for me personally and my office colleagues to search your web site at the very least thrice in one week to read the fresh things you have got. And indeed, I’m at all times pleased with your astounding methods you serve. Some 4 tips on this page are easily the most impressive we have all had.

  21. Thank you a lot for giving everyone a very marvellous chance to check tips from this site. It’s always so nice and packed with amusement for me personally and my office colleagues to search your blog no less than thrice a week to read through the newest stuff you have. And definitely, I’m actually amazed concerning the splendid tactics served by you. Some 2 facts in this posting are absolutely the most suitable we have all had.

  22. I want to get across my admiration for your kind-heartedness giving support to those people that must have assistance with that topic. Your special commitment to getting the message up and down turned out to be extremely effective and have truly made professionals like me to realize their aims. Your own helpful facts denotes so much a person like me and much more to my fellow workers. Thanks a ton; from everyone of us.

  23. I happen to be writing to let you understand what a great experience my friend’s daughter found reading through your blog. She picked up too many details, which included what it’s like to possess an excellent giving mood to make many people without problems have an understanding of specific hard to do subject matter. You undoubtedly surpassed people’s expectations. Thanks for coming up with these good, trusted, informative as well as cool tips on your topic to Kate.

  24. I simply had to say thanks once again. I am not sure the things that I would’ve taken care of without the entire ideas documented by you over such a subject. It previously was a depressing situation for me personally, but witnessing a expert approach you dealt with that made me to jump over gladness. I am happier for your information and even sincerely hope you comprehend what an amazing job your are undertaking instructing the rest through your website. I know that you haven’t met all of us.

  25. I not to mention my friends ended up going through the excellent tips on your website while before long I had a horrible suspicion I never thanked the website owner for those secrets. All the young men came absolutely warmed to study all of them and have now quite simply been tapping into them. We appreciate you getting so kind and also for selecting some smart things most people are really desperate to learn about. My sincere apologies for not expressing gratitude to earlier.

  26. I am also commenting to make you understand of the cool discovery my cousin’s daughter had browsing your webblog. She realized lots of pieces, including what it’s like to possess an amazing teaching spirit to make other people easily fully grasp selected problematic matters. You truly did more than visitors’ desires. Many thanks for providing these productive, dependable, explanatory and as well as cool tips on this topic to Evelyn.

  27. Thank you for each of your labor on this site. Gloria loves participating in investigations and it is simple to grasp why. Most of us learn all of the dynamic medium you convey precious steps on the website and in addition improve contribution from people about this point then our simple princess is always becoming educated so much. Take pleasure in the remaining portion of the year. You’re the one performing a great job.

  28. My wife and i felt now ecstatic when Edward could finish off his analysis through your ideas he gained from your site. It’s not at all simplistic to just happen to be giving for free secrets which usually other people might have been trying to sell. We really realize we have got the writer to thank because of that. The type of illustrations you made, the simple website menu, the relationships your site assist to promote – it’s most remarkable, and it is facilitating our son in addition to us consider that this concept is awesome, which is certainly truly indispensable. Many thanks for everything!

  29. I want to get across my gratitude for your kind-heartedness supporting persons who absolutely need assistance with that study. Your very own dedication to getting the message all through came to be particularly informative and have surely made people much like me to get to their goals. This important guideline means a whole lot a person like me and even more to my office workers. Best wishes; from everyone of us.

  30. Thank you a lot for giving everyone an extraordinarily remarkable opportunity to discover important secrets from this site. It’s usually very pleasurable and as well , packed with a lot of fun for me and my office colleagues to search your site at the least thrice in one week to see the fresh items you have. Not to mention, I’m also usually pleased for the powerful concepts you serve. Selected 4 ideas in this posting are surely the most suitable we’ve had.

  31. I was really happy to discover this web-site. I intended to thanks for your time for this fantastic read!! I certainly appreciating every bit of it and I have you bookmarked to take a look at brand-new stuff you blog post.

  32. I definitely wanted to develop a quick remark in order to appreciate you for these marvelous tricks you are showing at this website. My time-consuming internet look up has finally been rewarded with reputable knowledge to exchange with my two friends. I ‘d say that we readers are very much endowed to dwell in a useful community with very many perfect people with good concepts. I feel truly grateful to have encountered your site and look forward to tons of more pleasurable minutes reading here. Thank you once more for a lot of things.

  33. I am also writing to let you be aware of of the perfect discovery my daughter went through checking your web site. She learned so many things, not to mention what it is like to possess an excellent giving mood to let many others without difficulty know several impossible subject matter. You undoubtedly surpassed my expected results. Many thanks for giving such priceless, safe, revealing and unique tips on this topic to Tanya.

  34. Thank you a lot for providing individuals with remarkably special chance to read in detail from this website. It is always so sweet and stuffed with a great time for me personally and my office fellow workers to visit your site no less than thrice per week to read the newest guides you will have. And indeed, I’m always motivated concerning the wonderful pointers you serve. Certain 2 tips on this page are easily the most beneficial I’ve had.

  35. I would like to express some thanks to the writer for bailing me out of this type of scenario. As a result of surfing through the the net and finding strategies that were not beneficial, I figured my entire life was well over. Living without the approaches to the issues you have resolved by way of your blog post is a critical case, as well as the ones that could have in a negative way damaged my entire career if I hadn’t discovered your site. Your main knowledge and kindness in dealing with all the stuff was important. I’m not sure what I would have done if I had not come upon such a thing like this. I can at this point look forward to my future. Thanks for your time very much for your professional and amazing guide. I will not think twice to endorse your web sites to any individual who ought to have recommendations about this problem.

  36. I am just writing to make you be aware of of the really good discovery my child enjoyed viewing yuor web blog. She even learned numerous pieces, with the inclusion of how it is like to have a very effective giving heart to have the rest without hassle grasp specified specialized topics. You really did more than our expectations. Thank you for distributing those necessary, dependable, educational and as well as fun tips on the topic to Emily.

  37. I must show thanks to you just for rescuing me from this type of circumstance. Just after looking throughout the internet and obtaining basics which were not helpful, I was thinking my life was done. Living without the presence of solutions to the issues you have fixed through the site is a critical case, and those which could have in a negative way damaged my career if I hadn’t encountered your web page. The skills and kindness in maneuvering the whole lot was important. I’m not sure what I would have done if I had not discovered such a subject like this. I can at this time relish my future. Thanks for your time so much for the high quality and results-oriented help. I won’t be reluctant to suggest your blog post to anyone who desires direction on this situation.

  38. I must show my appreciation to you for bailing me out of this instance. After searching through the world-wide-web and seeing views which are not productive, I figured my entire life was over. Existing without the presence of strategies to the difficulties you’ve solved by means of your blog post is a serious case, as well as those which might have badly affected my career if I hadn’t noticed the blog. Your good training and kindness in touching a lot of things was important. I am not sure what I would have done if I had not come across such a solution like this. It’s possible to now look ahead to my future. Thanks a lot so much for this high quality and result oriented guide. I won’t be reluctant to endorse your web page to anyone who would need guidance about this topic.

  39. My wife and i felt comfortable Raymond managed to finish off his investigation through the entire precious recommendations he discovered in your weblog. It is now and again perplexing to simply find yourself offering helpful tips that many some people have been making money from. And we all know we have got the writer to thank for that. The specific explanations you have made, the simple site navigation, the relationships you can make it possible to promote – it is many spectacular, and it’s really letting our son in addition to the family reckon that the situation is entertaining, which is certainly rather fundamental. Thank you for all!

  40. I have to express some appreciation to you just for rescuing me from such a setting. After checking throughout the world-wide-web and seeing suggestions which are not powerful, I figured my entire life was gone. Being alive devoid of the approaches to the issues you’ve resolved by way of your main guide is a serious case, and those which could have in a wrong way affected my entire career if I hadn’t noticed your web blog. Your competence and kindness in dealing with every aspect was crucial. I don’t know what I would’ve done if I hadn’t discovered such a solution like this. I can also at this point look forward to my future. Thanks for your time very much for the high quality and amazing guide. I won’t be reluctant to suggest the blog to any individual who should have guidance on this issue.

  41. My spouse and i got absolutely relieved when Raymond could complete his basic research using the ideas he gained from your very own blog. It’s not at all simplistic just to choose to be making a gift of tips which usually other folks have been selling. We really see we have the blog owner to appreciate for that. All of the explanations you made, the easy website menu, the relationships you will give support to instill – it’s all fantastic, and it is making our son and us understand that subject matter is enjoyable, and that is especially essential. Thank you for everything!

  42. Thanks so much for providing individuals with remarkably spectacular possiblity to read from this website. It is often so cool and as well , stuffed with amusement for me and my office peers to search your site a minimum of 3 times a week to study the new guides you will have. And of course, we’re at all times satisfied with all the surprising tips you give. Certain 3 points in this post are in fact the very best we have all had.

  43. I actually wanted to write a simple remark to thank you for these splendid tactics you are sharing at this site. My considerable internet look up has now been paid with wonderful suggestions to go over with my family and friends. I would assert that most of us readers are unequivocally blessed to live in a superb network with many awesome professionals with valuable tactics. I feel truly blessed to have seen your entire web pages and look forward to really more exciting minutes reading here. Thank you again for all the details.

  44. I’m just commenting to let you be aware of of the really good encounter my wife’s child had using your web site. She mastered such a lot of pieces, which include how it is like to have a wonderful coaching style to get other folks easily thoroughly grasp a variety of grueling subject matter. You really did more than her desires. Thanks for imparting such good, dependable, edifying and as well as fun tips about this topic to Mary.

  45. I simply wanted to post a comment in order to say thanks to you for all of the remarkable tips you are giving out on this website. My long internet research has now been honored with brilliant suggestions to exchange with my guests. I ‘d claim that most of us website visitors actually are unequivocally fortunate to live in a useful site with many wonderful professionals with beneficial secrets. I feel really blessed to have used the web page and look forward to really more excellent minutes reading here. Thanks once again for all the details.

  46. I just wanted to compose a brief word to be able to say thanks to you for those lovely strategies you are giving out at this website. My considerable internet look up has at the end of the day been compensated with reasonable suggestions to share with my close friends. I ‘d assume that we website visitors are extremely fortunate to live in a fantastic place with very many perfect individuals with valuable ideas. I feel pretty privileged to have come across your entire webpages and look forward to some more thrilling times reading here. Thanks again for a lot of things.

  47. I truly wanted to type a small word so as to thank you for these fantastic suggestions you are giving out at this site. My extensive internet look up has finally been honored with excellent suggestions to write about with my colleagues. I ‘d assume that we visitors actually are unquestionably endowed to live in a very good website with many brilliant people with helpful tactics. I feel very much privileged to have used your webpage and look forward to tons of more amazing moments reading here. Thank you again for a lot of things.

  48. A lot of thanks for each of your hard work on this web site. My mom takes pleasure in working on research and it is easy to understand why. Many of us notice all relating to the dynamic ways you create very useful items through this website and boost participation from other people about this area while our daughter has always been being taught a great deal. Take pleasure in the remaining portion of the year. You’re the one doing a powerful job.

  49. I would like to convey my affection for your kind-heartedness giving support to people that must have help on that idea. Your very own dedication to passing the solution all around appears to be certainly helpful and have helped girls just like me to achieve their endeavors. Your useful guide entails a great deal a person like me and additionally to my peers. Thanks a lot; from each one of us.

  50. I must convey my appreciation for your kindness giving support to folks who absolutely need assistance with this subject matter. Your real dedication to getting the message throughout has been remarkably important and have really empowered guys much like me to achieve their aims. The important instruction entails much a person like me and a whole lot more to my colleagues. Thank you; from everyone of us.

  51. Attractive part of content. I simply stumbled upon your
    site and in accession capital to assert that I get actually loved account your weblog posts.
    Anyway I will be subscribing in your augment or even I success
    you get entry to constantly fast.

    Feel free to visit my webpage; joe biden hat

  52. Thanks so much for giving everyone an exceptionally terrific chance to read from this blog. It’s always so nice and as well , stuffed with a great time for me personally and my office acquaintances to visit your site at the least thrice per week to read through the fresh stuff you have got. And lastly, I’m also at all times amazed with all the amazing points served by you. Selected 2 points in this article are definitely the simplest we have had.

  53. My wife and i were fortunate Peter managed to finish off his basic research via the precious recommendations he received through your blog. It is now and again perplexing to simply be giving away procedures that many a number of people may have been making money from. And we all see we have got the blog owner to give thanks to for this. All of the illustrations you have made, the easy website menu, the friendships you make it possible to foster – it’s got most astonishing, and it’s aiding our son and our family understand that concept is enjoyable, which is certainly extraordinarily vital. Many thanks for all!

  54. I enjoy you because of every one of your efforts on this website. Betty really likes making time for internet research and it’s really obvious why. Most people learn all relating to the lively means you create very helpful tips and tricks by means of this blog and as well as strongly encourage response from other ones on the concern and my simple princess is now becoming educated a lot. Take pleasure in the rest of the year. You are always doing a brilliant job.

  55. I have to express my thanks to this writer just for rescuing me from this type of issue. Right after looking out through the the net and coming across techniques which are not powerful, I figured my life was over. Being alive without the strategies to the difficulties you’ve solved by means of this guideline is a critical case, and ones that would have negatively damaged my entire career if I hadn’t come across your web site. Your primary skills and kindness in maneuvering all areas was important. I don’t know what I would’ve done if I hadn’t come upon such a point like this. I can at this time look forward to my future. Thanks for your time so much for this skilled and results-oriented help. I will not hesitate to recommend your web site to anybody who wants and needs guide about this area.

댓글 남기기